UNPKG

1.55 kBMarkdownView Raw
1
2# Igo cache
3
4Igo uses Redis as a distributed cache.
5
6This is the default Redis configuration :
7```js
8
9var retryStrategy = function(params) {
10 if (params.error.code === 'ECONNREFUSED') {
11 logger.error('Redis connection refused on host ' + options.host + ':' + options.port);
12 return params.error;
13 }
14 logger.error('Redis error ' + params.error);
15 // retry in n seconds
16 return params.attempt * 1000;
17};
18
19config.redis = {
20 host: process.env.REDIS_HOST || 'localhost',
21 port: process.env.REDIS_PORT || 6379,
22 database: process.env.REDIS_DATABASE || 0,
23 timeout: null, // no timeout by default
24 no_ready_check: true,
25 retry_strategy: retryStrategy
26};
27```
28
29This configuration object is directly transmitted to the redis client: `redisclient = redis.createClient(config.redis);`
30
31Use `require('igo').cache` to access the Igo Cache API.
32
33```js
34
35var cache = require('igo').cache;
36var id = 123;
37cache.put('namespace', id, 'hello', function() {
38 cache.get('namespace', 124, function(err, value) {
39 assert(value === 'hello');
40 });
41});
42
43```
44
45## API
46Available functions are:
47- `get(namespace, id, callback);`
48- `put(namespace, id, value, callback);`
49- `fetch(namespace, id, fn, callback);` (where fn(id, callback) is called only if key is not found in cache)
50- `info(callback)`
51- `del(namespace, id, callback)`
52- `flushall(callback)`
53
54## Special note about Dates
55Since javascript Dates are ISO_8601 formatted and stored as strings in Redis, Igo automatically parses dates when they are retrieved from the cache.