'Cache control header not working

I have set Cache control in my response header as Cache-Control:public, max-age=86400. But when I try to refresh page or open a new tab, it always hits my server. The response status I got is 200, server log is appeared for this request also I checked chrome://cache/ this request is not in the list. I already looked some similar SO questions cache-control not working without etag and why cache-control:max-age don't work?. But still with no luck. Tested on chrome 56.



Solution 1:[1]

Chrome disables cache when DevTools is open, or at least it does Chrome 59. Open DevTools, go to Network, uncheck "Disable cache" at the top. Now you should be able to refresh the page and see it in chrome://cache.

Solution 2:[2]

Cache control tells your browser (and proxy servers like Squid) what resources it cannot cache. But it does not force your browser to cache a resource.

Solution 3:[3]

I recommend to check the error_logs to see if you really go to the backend, or stay in the browser.

In my case, browser gives me 200OK in the console logs but I don't reach the back end according to the error_log ...

Solution 4:[4]

Cache-Control response header will not work for page refresh. Try making that request twice without refreshing the page, then you will see it being cached (the request won't reach your server internally). To achieve what you want you might have to cache your request by accessing localStorage, or just cache it through a back-end caching library.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mwp
Solution 2 Larry B.
Solution 3 Ricky Levi
Solution 4