1 module Hashtbl = MoreLabels.Hashtbl
3 module Msg = Khatus_msg
4 module Time = Khatus_time
7 { values : ((string * string * string list), string) Hashtbl.t
8 ; mtimes : ((string * string * string list), Time.t) Hashtbl.t
12 { values = Hashtbl.create 256
13 ; mtimes = Hashtbl.create 256
16 let update {values; mtimes} ~node ~modul ~key ~value:data ~time =
17 let key = (node, modul, key) in
18 Hashtbl.replace values ~key ~data;
19 Hashtbl.replace mtimes ~key ~data:time
21 let update_if_data t ~msg ~time =
23 | Msg.({content = Data {key; value}; node; modul}) ->
24 update t ~node ~modul ~key ~value ~time
25 | {Msg.content = Msg.Alert _; _}
26 | {Msg.content = Msg.Cache _; _}
27 | {Msg.content = Msg.Error _; _}
28 | {Msg.content = Msg.Log _; _}
29 | {Msg.content = Msg.Status_bar _; _}
33 let dump {values; mtimes} ~node ~modul ~oc =
34 Hashtbl.iter values ~f:(fun ~key ~data:value ->
36 match Hashtbl.find_opt mtimes key with
38 | None -> assert false (* Implies update was incorrect *)
40 let (node', modul', key) = key in
45 ; content = Cache {mtime; node = node'; modul = modul'; key; value}