Cache.Ephemeral
Ephemeral(Key)
is a module that manages an ephemeral concurrent cache. An ephemeral cache is one whose bindings are deleted as soon as its keys go out of scope.
Note that this module overrides a couple of functions to clean the cache i.e. remove dead bindings (modulo a full GC cycle):
length
always cleans the cachefind
probabilistically cleans the cache with a 1/8 likelihoodval access : 'a t -> ('a Table.t -> 'b) -> 'b Lwt.t
access(cache, f)
runs the function f
on the hash table contents of the cache
, returning the result value. It can be used to both read from and write to the cache.
f(table)
is a callback which has locked access to the hash table
contained in the cache
and can do anything with it, including multiple operations like checking if the cache contains a key, then adding it or not.
Since this does lock the cache, it is preferable to not do long-running operations here, and to finish and unlock as quickly as possible.
val length : 'a t -> int Lwt.t
val make : unit -> 'a t
make()
allocates a new cache value.
val reset : 'a t -> unit Lwt.t