express-redis-cache
express-redis-cache copied to clipboard
setting res.use_express_redis_cache=false in error handler
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().
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,
},
});
This has been resolved now @pswoodworth, so @artursudnik should be able to use this now.
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.
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 absolutely! please send a PR to the dev branch.
What ended up happening with this issue? Are error results still being cached?