# redis-cache-express-middleware

> a middleware use for express to store same request by redis

Latest version **1.0.4** (published 2018-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install redis-cache-express-middleware
pnpm add redis-cache-express-middleware
yarn add redis-cache-express-middleware
bun add redis-cache-express-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-04-01 |
| First published | 2018-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | https://github.com/GeaJiang |
| Maintainers | gea |

## Links

- npm: https://www.npmjs.com/package/redis-cache-express-middleware
- Repository: https://github.com/GeaJiang/redis-cache-express-middleware
- Homepage: https://github.com/GeaJiang/redis-cache-express-middleware#readme
- Issues: https://github.com/GeaJiang/redis-cache-express-middleware/issues
- npm.io page: https://npm.io/package/redis-cache-express-middleware

## Dependencies (2)

- [redis](https://npm.io/package/redis.md) ^2.8.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1

## Recent versions

- 1.0.4 (latest) — 2018-04-01
- 1.0.3 — 2018-03-31
- 1.0.2 — 2018-03-31

## README

# redis-cache-express-middleware
a middleware for express to store same request by redis

there are some configuration for redis
```javascript
let config = {
  db: 1,
  host: '127.0.0.1',
  post: 6379,
  limit: 200,
  structure: 'LFU',
  password: '1234',
  clearTime: '12:00',
  interval: 60 * 60 * 24
}
```
db is select redis db

host is redis host

port is redis port

limit is to limit store total apis data

structure is i provide three algorithm to store data

password is redis password

clearTime and interval is clear all cache data automatically, for example if we set clearTime is '12:00' ,interval is 60 * 60 * 24  , redisCache will clear data at 12:00 everyday

we can use cache() as a middleware to get data from redis instead of database , don't need to calculate data again if we have done before;
example:

```javascript

const RedisCache = require('../index');

const redisCache = new RedisCache();

app.get('/foo', redisCache.cache('foo', 'blah'), (req, res) => res.json({a:1}));
app.get('/bar', redisCache.cache('bar'), (req, res) => res.json({b:1}));
app.get('/', redisCache.cache('foo', 'bar'), (req, res) => res.send('aaaa'));

```

if there are some operations make data in redis stale, we can use method update() to update data or just tell redis the data is stale, then we will get fresh data from redis or recaculate data or get data from database.
```javascript
app.put('/foo', (req, res) => {
  redisCache.update('foo', 'blah', {a:2});
})

app.put('/bar', (req, res) => {
  redisCache.update('foo', null, {b:2});
})

app.put('/', (req, res) => {
  redisCache.update('foo', 'bar');
})
```

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