lru-memoizer
Installation
npm i lru-memoizer --saveIntro
Usage
var memoizer = require('lru-memoizer');
var memoizedGet = memoizer({
//defines how to load the resource when
//it is not in the cache.
load: function (options, callback) {
request.get(options, callback);
},
//defines how to create a cache key from the params.
hash: function (options) {
return options.url + qs.stringify(options.qs);
},
//don't cache in test environment
disable: isTestEnv(),
//all other params for the LRU cache.
max: 100,
maxAge: 1000 * 60
});
memoizedGet({
url: 'https://google.com',
qs: { foo: 123 }
}, function (err, result, body) {
//console.log(body);
})
Sync lru-memoizer
Similar modules
License
Last updated