Create a new Function that returns the memoized results of a
Function. The key for the lookup cache is determined by the
keyExtractor Function.
An optional Map instance can be provided to be used as cache. This
allows for example to prepopulate the cache, or to force recomputation of
some values by removing their corresponding keys. If no instance is provided
an empty Map will be created.
Remarks
The memoized function should be a pure function, because else side effects
will only be executed once for each cached key.
Example
Memoize an expensive function
constexpensiveFunction = (a, b) =>a + b; constkeyExtractor = (a, b) =>`${a}_${b}`;
Create a new Function that returns the memoized results of a Function. The key for the lookup cache is determined by the
keyExtractorFunction.An optional Map instance can be provided to be used as cache. This allows for example to prepopulate the cache, or to force recomputation of some values by removing their corresponding keys. If no instance is provided an empty Map will be created.
Remarks
The memoized function should be a pure function, because else side effects will only be executed once for each cached key.
Example
Memoize an expensive function
Example
Provide an initial cache restored from database
Example
Clear cache after 5 seconds
Returns
the memoized result