p-async-cache
Cache the promise lookups and avoid fetching the same thing more than necessary.
Install
$ npm install p-async-cache --save
Usage
let counter = 0const cache = async { counter ++ return await } { cache} // [object User] 1// [object User] 1 (The counter still be 1)
new AC(options)
- options
Object=
- stale
Boolean
whether allow stale value - stringify
function()=JSON.stringify
method to serialize theparams
to a cache key. - load
AsyncFunction(...params)|function(...params):Promise|function(...params)
accepts a normal synchronous function, a function that returns a promise, or an async function, and theparams
will be the parameters of the.get(...params)
method. - other options that lru-cache supports
- stale
options.stale
Example for const cache = stale: true maxAge: 100 { return } cache
.get(...params)
- params
any
that will be passed intooptions.load(...params)
Returns Promise
Lookup the value in the cache,
- if found, then return.
- if not found,
- if allow stale values, and the value is stale, then return the value, and refresh value in background.
- otherwise, load the value with
load(...params)
lru-cache
Other methods of .reset()
.has(...params)
.peek(...params)
.del(...params)
License
MIT