CNN Caching
Makes working with caching easier. Now with hash ring support!
Fork of mape/node-caching
Installation
Via npm:
$ npm install cnn-caching
Built in stores
- Memory
- Redis
- Hash Ring
Pseudo-code Example
var Caching = ;var cache = 'redis'; /* use 'memory', 'redis' or 'hashring' */ var ttl = 60 * 1000; // 1minute;;
Memory Code Example
var Caching = ;var cache = ; ;
Redis Code Example
var Caching = ;var cache = 'redis'; ;
Hash Ring Code Example
var Caching = ;var cache = 'hashring' "servers": 'http://localhost:6377,http://localhost:6378,http://localhost:6379,http://localhost:6380' "max cache size": 10000 /* Any node-hashing options allowed */ "minTtl": 10 /* Minimum TTL that cnn-caching will actually cache (default 0) */ ; ;
Api
cache(key, ttl, runIfNothingInCache, useReturnedCachedResults);
arguments[0]
Key, 'myKey'
arguments[1]
Time To Live in ms, 60*30*1000
arguments[2]
Callback that will run if results aren't already in cache store.
{ ;}
arguments[3]
Callback that is called every time the method runs.
{ console;}