redis-cache

A short-term redis caching module for passing data around by keys

redis-cache

Super simple redis-based single-lookup caching for Node.js designed as a temporary storage for Hook.io

$ npm install redis-cache

Example using Hook.io (obviously very simplified)

var cache = require('redis-cache');
 
cache.init('redis://...');
 
hook.emit('doSomething', 'data', function(errkey) {
    if (err) {...}
    cache.fetch(key, function(errreallyBigResult) {
        if (err) {...}
        
        // ... 
        
    });
});
var cache = require('redis-cache');
 
cache.init('redis://...');
 
hook.on('*::doSomething', function(datacallback) {
    doSomething(data, function(errreallyBigResult) {
        if (err) {...}
        cache.store(reallyBigResult, function(errkey) {
            if (err) {...}
            callback(null, key);
        });
    });
});

The redisCache.init method can take a redis url as a paramter as shown above, or a config object.

{
    "url": "redis://...",
    "expire": 600
}

The expire value is how long (in seconds) a value is held in cache.