buffering-cache
Cache a little cold? Cache misses slowing you down?
buffering-cache
keeps your cache warm asynchronously. Minimizing cache misses and keeping the entries from becoming stale.
Currently works with Redis only. Welcoming PRs for memcached or any other in-memory database.
Also offers a multi-level cache option. In addition to Redis, you can use local memory cache courtesy of lru-cache before failing over to a remote Redis instance.
Installation:
npm install --save buffering-cache
Simple Example:
const BufferingCache = require('buffering-cache');
const rp = require('request-promise');
const bufferingCache = new BufferingCache({
host: 'localhost',
port: 6379,
ttlMsec: 5000
});
const rawFunction = () => rp('http://www.google.com');
const bufferedAndCachedFunction = bufferingCache.wrapFunction(rawFunction);
bufferedAndCachedFunction()
.then((response) => {
})
.delay(3000)
.then(() => {
return bufferedAndCachedFunction();
})
.then(() => {
return bufferedAndCachedFunction();
})
.delay(3000)
.then(() => {
return bufferedAndCachedFunction();
})
Configuration
const configuration = {
host: 'localhost',
port: 6379,
ttlMsec: 500,
db: 0,
keyPrefix: '',
bufferTtlMsec: 500,
localCacheSize: 0,
localTtlMsec: 500
};
const bufferingCache = new BufferingCache(configuration);