p-cache
Decorator to memoize the results of async functions via lru-cache.
Features
- Uses lru-cache for caching impl
- Uses object-hash for implicit cache key derivation from function args
- Thoroughly tested in production
Install
npm install --save p-cache
Usage
const request = const pCache = label: 'test-service' // pass args to lru-cache here max: 1000 // returns an async function which gets the given url, with the results being // cached via lru-cache up to 1000 urlsmoduleexports =
API
function pCache(opts)
Returns a function decorator that will wrap calls to the target function in an lru-cache instance defined by these opts
.
opts
- object, optionalopts.label
- string, optional label to use for displaying cache hits and missesopts.log
- function, optional function to use for displaying cache hits and misses (default:console.log
)
Note all unrecognized options are passed onto lru-cache
opts.max
- number, optional passed onto lru-cacheopts.maxAge
- number, optional passed onto lru-cacheopts.length
- function, optional passed onto lru-cacheopts.dispose
- function, optional passed onto lru-cacheopts.stale
- boolean, optional passed onto lru-cacheopts.noDisposeOnSet
- boolean, optional passed onto lru-cache
pCache(opts) => Function<Promise>(async function(...args))
License
MIT © Travis Fischer