datastructures provides simple ways to cache return values of pure functions.
‣ MemoizeFunction ( function[, options] ) | ( function ) |
Returns: A function
MemoizeFunction
returns a function which behaves the same as function, except that it caches the return value of function. The cache can be flushed by calling FlushCaches
(Reference: FlushCaches).
This function does not promise to never call function more than once for any input -- values may be removed if the cache gets too large, or GAP chooses to flush all caches, or if multiple threads try to calculate the same value simultaneously.
The optional second argument is a record which provides a number of configuration options. The following options are supported.
flush
(default true
)If this is true
, the cache is emptied whenever FlushCaches
(Reference: FlushCaches) is called.
contract
(defaults to ReturnTrue
(Reference: ReturnTrue))A function that is called on the arguments given to function. If this function returns false
, then errorHandler
is called.
errorHandler
(defaults to none)A function to be called when an input that does not fulfil contract
is passed to the cache.
generated by GAPDoc2HTML