# elefrant-redis-cache

> Restify cache using Redis

Latest version **0.1.2** (published 2014-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install elefrant-redis-cache
pnpm add elefrant-redis-cache
yarn add elefrant-redis-cache
bun add elefrant-redis-cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-06-26 |
| First published | 2014-06-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Gergely Nemeth |
| Maintainers | marsanla |
| Keywords | redis, restify, cache |

## Links

- npm: https://www.npmjs.com/package/elefrant-redis-cache
- Repository: https://github.com/Elefrant/elefrant-redis-cache
- Issues: https://github.com/Elefrant/elefrant-redis-cache/issues
- npm.io page: https://npm.io/package/elefrant-redis-cache

## Dependencies (1)

- [redis](https://npm.io/package/redis.md) ~0.10.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-06-26
- 0.1.1 — 2014-06-25
- 0.1.0 — 2014-06-24

## README

Elefrant-redis-cache
-------------
Based on the query string and [restify-cache](https://github.com/gergelyke/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()](http://mcavage.me/node-restify/#Response-API) method will control the [EXPIRE](http://redis.io/commands/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

---
_Source: https://npm.io/package/elefrant-redis-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
