Memoize promise-returning & async functions
Useful for speeding up consecutive function calls by caching the result of calls with identical input.
$ npm install p-memoize
const pMemoize = require('p-memoize');
const got = require('got');
const memGot = pMemoize(got, {maxAge: 1000});
(async () => {
memGot('sindresorhus.com');
// This call is cached
memGot('sindresorhus.com');
setTimeout(() => {
// This call is not cached as the cache has expired
memGot('sindresorhus.com');
}, 2000);
})();
Returns a memoized version of the fn
function.
Type: Function
Promise-returning or async function to be memoized.
Type: Object
See the mem
options.
Clear all cached data of a memoized function.
Will throw if passed a non-memoized function.
- p-debounce - Debounce promise-returning & async functions
- p-throttle - Throttle promise-returning & async functions
- More…
MIT © Sindre Sorhus