Library
Module
Module type
Parameter
Class
Class type
Simple cache with dependencies and timeout.
val make :
?dep:'b t ->
?new_if:('a t -> bool) ->
?timeout:float ->
?debug:bool ->
string ->
('a option -> 'a) ->
'a t
make key f
create a new cache to hold the return value of f
using the key
. f
is given its previously returned value if any — it may be less work to update it than recreating it afresh. The disk cache will be updated when the program exits, so its content will persist across multiplie runs of the program. The type 'a
must be marshal-able.
val update : ?f:('a option -> 'a) -> 'a t -> unit
update t
update the cache immediately. If f
is given, first set the function generating values for the cache t
to f
and then update the cache by running f
.
depend t t'
says that the cache t
depends on the cache t'
i.e. that before updating t
, one must update t'
.
val get : ?update:bool -> 'a t -> 'a
Get the value stored in the cache. This operation will update the cached value if necessary.
val result :
?dep:'b t ->
?new_if:('a t -> bool) ->
?timeout:float ->
?debug:bool ->
string ->
('a option -> 'a) ->
'a
result key f
is a convenience function equivalent to get(make key f)
.
val time : 'a t -> float
The time of the last update of the cache. Returns neg_infinity
if the cache is not initialized.
val key : 'a t -> string
key t
returns the key used to store the value.