1.3.0 • Published 3 years ago

@empy/express-redis v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

release Version

@empy/express-redis

Install

npm install @empy/express-redis

Usage

Configuration options

KeyTypeDefaultDescription
ttlnumber86400Duration, in seconds, to retain the cached value.
debugbooleanfalseEnable debug messages.

Redis Client

This module is not meant to manage the redis connection. It is expected that the app using it to manage the redis configuration.

It is written to work with the node-redis client. See the documentation for the client-configuration.

Express app

  const redis = require('redis')
  const expressRedis = require('@empy/express-redis')

  const client = redis.createClient()
  await client.connect()

  const config = {} // See configuration options
  const { cacheMiddleware } = expressRedis(config, redisClient)

Routing

General routing

It can be used to cache all matching express routes, identified by a path or a regexp.

  const app = express()

  app.use('/path/to/cache', cacheMiddleware)
  app.use('/regexp_to_match/', cacheMiddleware)

Specific caching

It can also be used route by route, by chaining the middleware in the route declaration.

  const app = express()

  app.get('/route_to_cache', cacheMiddleware, (req, res, next) => {...})

Test

We use Mocha and Should for the tests. You can invoke tests like this:

npm run test
1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago