memory-cacher
v1.1.1
Published
cache and get asynchronous values
Downloads
11,458
Maintainers
Readme
memory-cacher
get value from cache or from asynchronous getter, it will also call the promise only once in case it will ask for the same key more than once
Usage
@param {string} key @param {asynchronous function} fn @param {int} expiration
const MemoryCacher = require('memory-cacher');
const key = 'key';
let result = await MemoryCacher.getCached(key);
// result === null
result = await MemoryCacher.getCached(key, async () => {
await delay(100);
return 10;
}, 200);
// result === 10
result = MemoryCacher.getCached(key);
// result === 10