http-cache-middleware icon indicating copy to clipboard operation
http-cache-middleware copied to clipboard

Cannot read properties of undefined (reading 'get') when using [email protected]

Open alanskovrlj opened this issue 2 years ago • 1 comments

Describe the bug
When using [email protected] package for redis store throws the following error: "Cannot read properties of undefined (reading 'get')"

Reproduce:

  1. npm init, run redis server
  2. npm i http-cache-middleware cache-manager-ioredis restana [email protected]
  3. run following code from below
  4. Send http request to one of the endpoints
const CacheManager = require('cache-manager')
const redisStore = require('cache-manager-ioredis')
const redisCache = CacheManager.caching({
  store: redisStore,
  db: 0,
  host: 'localhost',
  port: 6379,
  ttl: 30
})
const middleware = require('http-cache-middleware')({
  stores: [redisCache]
})

const service = require('restana')()
service.use(middleware)

service.get('/cache', (req, res) => {
  setTimeout(() => {
    res.setHeader('x-cache-timeout', '1 minute')
    res.send('this supposed to be a cacheable response')
  }, 50)
})

service.delete('/cache', (req, res) => {
  res.setHeader('x-cache-expire', '*/cache-*')
  res.end()
})

service.start(3000)

alanskovrlj avatar Aug 11 '23 12:08 alanskovrlj

Update: seems to be working when downgrading cache-manager version to v4.1.0

alanskovrlj avatar Aug 15 '23 09:08 alanskovrlj