Minimalist cache function for redis
Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist.
node_redis is used for connections.
$ npm install --save r-cache
const rCache = require('r-cache');
const client = rCache.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
const text = rCache.cache('text', 60, () => {
return 'Lorem ipsum dolor sit amet ...';
});
Returns the item in the cache for the given key, if the item does not exist in the cache, the function passed will be executed and its result will be placed in the cache.
The key for store the item in the cache.
Type: string
Number of seconds for which the value should be cached.
Types: number
The function to be executed.
Type: Function
Same options as node_redis#rediscreateclient
. This returns the redis
client.
MIT © Hosmel Quintana