express-redis-cache icon indicating copy to clipboard operation
express-redis-cache copied to clipboard

setting res.use_express_redis_cache=false in error handler

Open artursudnik opened this issue 8 years ago • 6 comments

Hi,

Is it possible to switch off caching of error responses? Setting res.use_express_redis_cache=false in error handler has no effect because it is called after cache.route().

artursudnik avatar May 19 '16 15:05 artursudnik

Hey, I believe you should be able to do this by setting TTL to 0 for all error status codes, but that's not currently working (#59).

var cache = require('express-redis-cache')({
  expire: {
      2xx: 5000,
      //These currently don't work correctly
      4xx: 0,
      5xx: 0,
      xxx: 0,
    },
});

pswoodworth avatar May 31 '16 21:05 pswoodworth

This has been resolved now @pswoodworth, so @artursudnik should be able to use this now.

ckeboss avatar Jun 30 '16 16:06 ckeboss

I tried this appraoch,unfortunately I still get cached results for error pages, and even worse, with a wrong status code. the issues happens for dynamic routes. e.g. /:city/:name if the city is not found, the route does a "next()" which can lead to a 404.. this gets somehow cached, and next time a 200 status coe with the error page is returned.

simllll avatar Jul 16 '16 15:07 simllll

Ran into this as well, shouldn't express-redis-cache check after the route completes as well?

I can see here ( https://github.com/rv-kip/express-redis-cache/blob/06928aa87d084336bde4ceb4db2c6bed97a1eabd/lib/ExpressRedisCache/route.js#L74-L77 ) that we check res.use_express_redis_cache to bypass the cache (calling next()), but in the wrapped res.send() ( https://github.com/rv-kip/express-redis-cache/blob/06928aa87d084336bde4ceb4db2c6bed97a1eabd/lib/ExpressRedisCache/route.js#L180-L207 ), we could also check to see if it has been set by the route / middleware.

@rv-kip I think I could easily submit a PR, would you accept one?

weisjohn avatar Jul 27 '17 18:07 weisjohn

@weisjohn absolutely! please send a PR to the dev branch.

krazyjakee avatar Aug 10 '18 11:08 krazyjakee

What ended up happening with this issue? Are error results still being cached?

jordancue avatar Apr 22 '19 13:04 jordancue