express-redis-cache
express-redis-cache copied to clipboard
Should set the Cache-Control header
Without the Cache-Control header, browsers will make unnecessary calls to the server to get cached data. If the browser is aware of the cache duration, it can avoid calling the server at all until the cache is expired. This could be done by adding a header like this:
res.setHeader('Cache-Control', 'max-age=' + options.expire + '000');
Good idea. I'm pretty busy at the moment, so I welcome a pull request :) I think the Cache-Control header should be a configuration option.
+1
It should definitely be a new opt in configuration option, there is valid use case where you'd want to have the redis cache but not set the cache-control header
submitted the PR https://github.com/rv-kip/express-redis-cache/pull/134 that add an option to opt-out of this behaviour, also fixed the cache-control header to handle different expiration based on the response status code