# seneca-redis-cache

> Redis caching plugin for seneca

Latest version **0.2.0** (published 2015-04-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-04-30 |
| First published | 2014-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | darsee, rjrodger, nherment |
| Keywords | seneca, cache, redis, plugin |

## Links

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

## Dependencies (1)

- [redis](https://npm.io/package/redis.md) ^0.10.1

## 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.2.0 (latest) — 2015-04-30
- 0.1.0 — 2014-10-14
- 0.0.2 — 2014-04-04
- 0.0.1 — 2014-03-26

## README

# seneca-redis-cache

### Node.js Seneca redis caching module.

This module is a plugin for the [Seneca framework](http://senecajs.org). It provides a set of common caching actions (`get`, `set` etc.), backed by [redis](https://github.com/mranney/node_redis).

By moving cache operations into Seneca, you can change your cache implementation or business rules at a later point.
For example, you might decide to send certain kinds of keys to a different cache mechanism, such as redis.

### Quick example

This code snippet sets a value and then retrieves it.

```JavaScript
var seneca = require('seneca')();
seneca.use('redis-cache');

seneca.ready(function(err) {
  seneca.act({role: 'cache', cmd: 'set', key: 'k1', val: 'v1'}, function(err) {
    seneca.act({role: 'cache', cmd: 'get', key: 'k1'}, function(err, out) {
      console.log('value = ' + out)
    });
  });
});
```

The full action argument pattern can be a bit tedious, so use a Seneca _pin_ to make things more convenient:

```JavaScript
var cache = seneca.pin({role:'cache', cmd:'*'});

cache.set({key: 'k1', val: 'v1'}, function(err) {
  cache.get({key:'k1'}, function(err, out) {
    console.log('value = ' + out);
  });
});
```
## Install

```sh
npm install seneca
npm install seneca-redis-cache
```

## Common Cache API

Seneca has a common caching API with the following actions:

   * `role:cache, cmd:set` store a value - _key_ and _val_ arguments required
   * `role:cache, cmd:get` retreive a value - _key_ argument is required
   * `role:cache, cmd:add` store a value, only if the key does not exist - _key_ and _val_ arguments required
   * `role:cache, cmd:delete` delete a value - _key_ argument is required, no error if key does not exist
   * `role:cache, cmd:incr` increment a value - _key_ and _val_ (integer) arguments required
   * `role:cache, cmd:decr` decrement a value - _key_ and _val_ (integer) arguments required

All caching plugins, including this one, implement this action API.

## Extended API

To access the underlying [redis](https://github.com/mranney/node_redis), use the action `plugin: 'redis-cache', cmd: 'native'`.

The plugin also registers with the action `role: 'seneca', cmd: 'close'`. This sends the `QUIT` command to the redis connection when you call the `seneca.close` method.

### Options

You can use any of the options from the node [redis](https://github.com/mranney/node_redis#rediscreateclientport-host-options) module directly as options to this plugin.

## Test

```bash
mocha test/cache.test.js
```

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