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

Should set the Cache-Control header

Open josh-egan-ps opened this issue 9 years ago • 4 comments

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');

josh-egan-ps avatar May 16 '16 16:05 josh-egan-ps

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.

rv-kip avatar May 16 '16 18:05 rv-kip

+1

Arwid avatar Oct 18 '16 20:10 Arwid

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

rawpixel-vincent avatar Jul 17 '21 13:07 rawpixel-vincent

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

rawpixel-vincent avatar Jul 17 '21 13:07 rawpixel-vincent