Version of the function that caches results.
import { memoize } from '@pacote/memoize'
const randomFunction = (prefix: string) => `${prefix}${Math.random()}`
const memoizedFunction = memoize((prefix) => `key_${prefix}`, randomFunction)
memoizedFunction('foo') // 'foo' followed by randomly-generated number.
memoizedFunction('foo') // Same result as previous call with 'foo'.
memoizedFunction('bar') // 'bar' followed by randomly-generated number.
memoizedFunction('bar') // Same result as previous call with 'bar'.
Returns a wrapper that caches a function's result for each generated key.
Repeated calls with the same key return the first result without invoking the wrapped function again. Set
capacityto evict least recently used entries when the cache grows beyond the limit.