0.1.2 • Published 10 years ago

elefrant-redis-cache v0.1.2

Weekly downloads
1
License
ISC
Repository
github
Last release
10 years ago

Elefrant-redis-cache

Based on the query string and restify-cache, it will store/retrieve JSON responses from Redis.

Usage

var cache = require('elefrant-redis-cache');
cache.config({
redisPort: 6379,        //default: '6379'
redisHost: 'localhost', //default: 'localhost'
redisOptions: {},       //optional
ttl: 60 * 60            //default:  60 * 60; in seconds
});

The first middleware after auth (if there is any) should be the cache's before.

server.use(cache.before);

You have to subscribe for the server's after event as well.

WARNING! In your route handlers, you always have to call next()!

server.on('after', cache.after);

Cache Control

Use of Restify's res.cache() method will control the EXPIRE time in Redis. The absence of a response cache will use the cache.config.ttl value identified above.

Indicates that the response should be cached for 600 seconds. (PUBLIC | PRIVATE | NO-CACHE | NO-STORE)

res.cache('public', {maxAge: 600});

A maxAge value of 0 will engage Redis, but set the expire seconds to 0 (essentially expiring immediately).

res.cache('public', 0);

Additional Headers

A header is added to each response:

  • X-Cache: HIT - the response was served from cache
  • X-Cache: MISS - the response generation fell through to the endpoint
0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago