0.1.5 • Published 5 years ago

cache-response v0.1.5

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

Installation

npm install response-cache

Example

// create redisClient
const redis = require('redis')
const ResponseCache = require('response-cache')
const redisClient = redis.createClient()
const responseCache = ResponseCache(redisClient)

const options = {
	duration: 60 // seconds,
}

app.get('/api/example', responseCache.cache(option), (req, res) => {
	  res.send('GET request to the homepage')
  })
  
// Cache all routes
app.use(responseCache.cache(option))

Clear cache

// create redisClient
const redis = require('redis')
const ResponseCache = require('response-cache')
const redisClient = redis.createClient()
const responseCache = ResponseCache(redisClient)

// manually
app.get('/api/clear', (req, res) => {
	responseCache.clear('key') // clear cache for key in redis
	res.send('clears cache')
  })  

options object properties

PropertyDefaultDescription
duration12 hoursttl in redis
keyreq.originalUrlkey in redis
prefix_keystring: key in redis has a same prefix to facilitate remove multiple keys
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago