fastify-caching
fastify-caching copied to clipboard
Only set cache for 200, 301 and 302 response
Currently cache-control header is sent for even 404 response. Can we avoid it?
Thanks for reporting this!
It definitely should, would you like to send a PR?
You should add a check for the status codes in https://github.com/fastify/fastify-caching/blob/master/plugin.js#L43-L52.
I am talking about this line: https://github.com/fastify/fastify-caching/blob/master/plugin.js#L72
I think that should move to a onSend hook instead.
Well I thought about it and current one seems fine to me. I set cache control to private by default and when I need the response to be cached, I set the header with reply.header. If we move it there, there must be a check that it should not set cache-control header if something in the app has already set it.
Yes exactly.