Max cache management expires_in max-age does not work

I can not get the maximum cache control to work correctly, I used expires_in , with the result that the header is "Cache-Control: max-age = 86400, public, must-revalidate".

But still, the browser still sends the request to the server, at least it is defined as โ€œ304 not changedโ€, which means that the ETag / If-None-Match headers are working correctly.

I tested it with webrick on my localhost and on heroku, with chrome 45 and safari.

And no, my development tools do not open, and "disable cache" is not checked.

I also tried removing the ", must_revalidate: true" call to the expires_in method.

What am I missing?

Here is the output from the network in chrome: General: Remote address: 127.0.0.1: 3000 Request URL: http: //localtest.mehaps000/api/books Request method: GET Status code: 304 Not changed

Answer header: Access-Control-Allow-Origin: * Access-Control-Request-method: * Cache-Control: max-age = 86400, public, must-revalidate Connection: Keep-Alive Date: Tue, 08 Sep 2015 13:28:01 GMT Etag: W / "1f1b2d0b822830bc74e7c47a116205be" Server: WEBrick / 1.3.1 (Ruby / 2.2.1 / 2015-02-26) X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Request-Id: c70d4715-dcff-4558-85af-9d21556d406a X-Runtime: 0.553353 X-XSS-Protection: 1; Mode = block

Request header: Accept: Text / HTML, application / XHTML + XML, application / XML; d = 0.9, image / WebP, /; d = 0.8 Accept-Encoding: gzip, deflate, sdch Accept-Language: EN-US, en; d = 0.8, pt; d = 0.6, he; d = 0.4 Cache-Control: max age = 0 Connection: keep-alive Host: localtest.me: 3000 If-None-Match: W / "1f1b2d0b822830bc74e7c47a116205be" Update unstable-requests: 1 User-Agent: Mozilla / 5.0 ( Macintosh, Intel Mac OS X 10_10_3) AppleWebKit / 537.36 (KHTML, e.g. Gecko) Chrome / 45.0.2454.85 Safari / 537.36

And here is the ruby โ€‹โ€‹code:

before_action :cache_control, only: [:index, :show] def cache_control expires_in 1.day, public: true, must_revalidate: true end 
+1
caching ruby-on-rails browser-cache cache-control
source share
1 answer

Well, the headers are fine, it's just a meter of how the browser handles the reset button or keyboard shortcuts.

I found the answer here: stack overflow

Here are the results in chrome:

  • Pressing Enter in the address bar corresponds to "maximum age", and does not send a request to the server.
  • The reboot button or Cmd + R sends a request to the server with If-Modified-Since and returns 304 if the resource has not been changed since ...
  • Cmd + Shift + R sends a request to the server without if-Modified-Since
+1
source share

All Articles