Reusable single-purpose caching class for node
$ npm install --save node-chaching
const Cache = require('node-chaching');
// create a new Cache instance with a 10 sec TTL and a get Promise
// that provides values when a cache miss occurs
const myCache = new Cache(10, (key) => Promise.resolve({key, value: 10}));
const args = {
key: 'key-1',
options: {
opt1: [],
opt2: 'opt2'
}
};
// retrieve value for given key
const value = await myCache.get(args);
// delete key and its value from cache
myCache.del('key-1');
Apache-2.0 © Trey Briggs