Memory and persistent caching with various levels of control, based on a combination of lru-cache from Hato and an older memoization library for Gauche.
Analagous to the procedure form of define
but
automatically memoizes the function. Uses equal?
for
equality comparisons and reasonable defaults - for finer grained
control use memoize
.
Returns a memoized version of the procedure proc
. By
default uses a least-recently-used (LRU) cache, which can be tuned
with the following keyword arguments:
equal?
hash
from (srfi 69)
compute-size
is a procedure of two arguments, the key and
value to be stored, and defaults to a constant 1 per entry. After
every insertion the oldest elements will be removed until the size
is under size-limit
. You may find
(lambda (k v) (+ (object-size k) (object-size v)))
using object-size
from (chibi ast)
to be a
useful compute-size
.
If size-limit
is #f
then the cache is unlimited,
and a simple hash-table will be used in place of an LRU cache.
Equivalent to memoize except that the procedure's first argument
must be a pathname. If the corresponding file has been modified
since the memoized value, the value is recomputed. Useful to
automatically reflect external changes to a file-backed resource.
The additional keyword argument reloader?:
, if true,
indicates that the result of loading is itself a procedure which
should check for updates on each call.
Returns a memoized version of the procedure proc
which
stores the memoized results persistently in a file. Garbage
collection of the files is left as an external task for monitoring
tools or cron jobs.
Accepts the following keyword arguments:
Creates a new empty LRU object. The same keyword arguments as in
memoize
are available, except of course for cache
.
Looks up key
in the cache LRU. If not found returns #f,
unless compute
is given in which case compute
is
applied to key
to determine the return value. This does not
update the cache.
Identical to lru-ref except that it updates the cache on a miss.
Directly set a value in the cache.