6
votes

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.

3
Are you also sending a Last-Modified and/or ETag header in the response? - mwp
No, I didn't. As my understanding ETag is for validating same content on server to save bandwidth? But I don't want browser to make a request in the first place if cache is not expired. - Mengo
I have the same problem, In my case i have a reverse proxy in place , which sets cache control to response headers . Although the headers get applied .chrome still hits the server - Jeson Dias
Typical trap: Inspecting with chrome/firefox/etc. devtools disables the cache. Make sure that "Disable Cache" is not checked. - Karsten S.
When you press Refresh (F5) then cache is cleared. Check more detailed answer here stackoverflow.com/questions/10518493/… - Sergey Ponomarev

3 Answers

5
votes

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.

1
votes

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.

0
votes

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 ...