p-memoize
Memoize promise-returning & async functions
Useful for speeding up consecutive function calls by caching the result of calls with identical input.
Install
$ npm install --save p-memoize
Usage
const pMemoize = require('p-memoize');
const got = require('got');
const memGot = pMemoize(got, {maxAge: 1000});
memGot('sindresorhus.com').then(() => {
// this call is cached
memGot('sindresorhus.com').then(() => {
setTimeout(() => {
// this call is not cached as the cache has expired
memGot('sindresorhus.com').then(() => {});
}, 2000);
});
});
API
See the mem
docs.
The only difference is that this module does not cache rejected promises.
Related
- p-debounce - Debounce promise-returning & async functions
- p-throttle - Throttle promise-returning & async functions
- More…
License
MIT © Sindre Sorhus