Module Weberizer.Cache
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 off
using thekey
.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.- parameter timeout
the number of seconds after which the cached value must be refreshed (running
f
again). Default:3600.
. A non-positive value means no timeout.
- parameter debug
print messages on
stderr
about cache usage and refresh. The string argument is a prefix to these messages to be able to distinguish different caches. Default:""
i.e., no messages.
val update : ?f:('a option -> 'a) -> 'a t -> unit
update t
update the cache immediately. Iff
is given, first set the function generating values for the cachet
tof
and then update the cache by runningf
.
val depend : 'a t -> dep:'b t -> unit
depend t t'
says that the cachet
depends on the cachet'
i.e. that before updatingt
, one must updatet'
.
val get : ?update:bool -> 'a t -> 'a
Get the value stored in the cache. This operation will update the cached value if necessary.
- parameter update
if
true
, force an update. Default:false
.
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 toget(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.