memoize es-toolkit
Caches function results so it runs faster when called again with the same arguments.
Usage
memoize(func, options?)
Use memoize when you want to optimize performance by caching a function's execution results. When called again with the same arguments, it returns the cached result to avoid duplicate computations.
Use this with functions that take a single parameter. If your function takes multiple arguments, combine them into a single object or array.
If the argument is compared by reference, such as arrays or objects, you should provide a getCacheKey function to generate an appropriate cache key.
You can also use a custom cache.
Parameters
The function to memoize. It must accept only one argument.
options(object, optional): Memoization configuration options.cache(MemoizeCache<any, ReturnType<F>>, optional): The cache object to store results. Defaults to a newMap.getCacheKey((arg: Parameters<F>[0]) => unknown, optional): A function to generate cache keys. Required when using non-primitive values as arguments.
Returns
Returns the memoized function. It includes a cache property to access the internal cache.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.