Generic caching library
memoize ~destruct ~expire f
memoizes the results of f
.
`Keep_one
: only keeps the last result around`Keep_all
: (the default value) never delete any values from the cache`Lru n
: keep n
values in the cache and them removes the least recently
usedReturns memoized version of any function with argument unit. In effect this builds a lazy value.
These modules implement memoization and give you access to the cache. This, for instance, enables you to flush it.
This enables you to implement your own caching strategy and store.
Generic caching is based on separating the replacement policie and the
store and tying them together with Make
.
Replacement policy
This dictates when elements will droped from the cache.
This type is used to specify the signature of cps_create
. For instance
if cps_create
takes two arguments of types x
and y
:
type 'a with_init_args : x -> y -> 'a
cps_create ~f
is given in CPS form to enable chaining. (i.e. instead of
directly returning a value it applies f to this value).
Caching store
A Store
is the backend used to store the values in a cache. A store is
a key/value associative table.
A key value store.
cps_create
is given in CPS form to enable chaining.
see Cache.Strategy.cps_create for more information.
replace store ~key ~data
associated the data
to key
; remove any
previously existing binding.
A key value cache
Used to specify the type of the create and memoize function. This
describes the arguments required to initialise the caching strategy and
the store. For instance if the store doesn't take any argument (eg.:
Store.Table) and the strategy takes an int
(eg.: Strategy.Lru)
this type will be:
type 'a with_init_args = int -> 'a