From 17b0107ffe818496d3463c88cedf94fb0e9aa3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Mon, 7 Dec 2020 21:20:24 +0100 Subject: [PATCH] Cache invalidation --- lib/model.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/model.ml b/lib/model.ml index 7df2925..0511a55 100644 --- a/lib/model.ml +++ b/lib/model.ml @@ -45,15 +45,21 @@ let read_full t path run = Bos.OS.File.read f >>= fun s -> Builder.Asn.exec_of_cs (Cstruct.of_string s) >>| fun (job_info, uuid, out, start, finish, result, data) -> - { meta = { job_info; uuid; start; finish; result }; - out; data } + let meta = { job_info; uuid; start; finish; result } in + t.cache <- RunMap.add (path, run) meta t.cache; + { meta; out; data } let read_full_meta t path run = match RunMap.find_opt (path, run) t.cache with - | Some meta -> Ok meta + | Some meta -> + Bos.OS.File.exists Fpath.(t.dir // path // run / "full") >>= fun exists -> + if exists + then Ok meta + else + (t.cache <- RunMap.remove (path, run) t.cache; + Error (`Msg "no such file")) | None -> read_full t path run >>| fun { meta; out = _; data = _ } -> - t.cache <- RunMap.add (path, run) meta t.cache; meta let job t job =