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. Requires an 'ioredis' Redis client to be provided.
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 Redis = require('ioredis');
const bufferingCache = new BufferingCache({
redisClient: new Redis({
host: 'localhost',
port: 6379,
db: 0,
}),
ttlMsec: 5000,
bufferTtlMsec: 2500,
localCacheSize: 0,
localTtlMsec: 500
});
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();
})