Memoize functions - an optimization technique used to speed up consecutive function calls by caching the result of calls with identical input
MIT License
Bot releases are visible (Hide)
mem
to memoize
4756892memDecorator
named import to memoizeDecorator
4756892memClear
named import to memoizeClear
4756892https://github.com/sindresorhus/mem/compare/v9.0.2...v10.0.0
Options
type (#88) 9a937d0.decorator()
is used (#75) d21357c.decorator()
method for TypeScript users (#61) 528fa42.clear(fn)
if fn’s cache can't be cleared (#59) e7c8893https://github.com/sindresorhus/mem/compare/v6.1.1...v8.0.0
What happened to v7? This version was prematurely published as v7, so we did v8 to prevent breaking for those already on v7.
cacheKey
(#43) b7a0766cacheKey: x => x
instead of the much more complicated previous default. This means it will now only cache the first argument, and only if it's a primitive. Previously, it tried to cache all arguments using JSON.stringify()
, but this was both error-prone and slow. This change makes the memoization logic very straightforward, explicit and fast by default. See the readme for how to handle multi-argument or non-primitive value situations.cachePromiseRejection
option (#43) b7a0766mem
and we plan to add it to p-memoize
instead (https://github.com/sindresorhus/p-memoize/issues/11), which is like mem
, but focused on promises..clear()
is called with a non-memoized function (#44) c73c23bEnhancements:
Breaking:
cachePromiseRejection
option to true
(#36) 70707aeBreaking for TypeScript users:
import mem from 'mem';
to import mem = require('mem');
Enhancements:
mimicFn
call (#26) e08ad85