expires_in max-age缓存控制不起作用

我无法让max-age缓存控件正常工作,我使用expires_in导致“Cache-Control:max-age = 86400,public,must-revalidate”标头。

但是,浏览器仍然将请求发送到服务器,至少它被定义为“304 not modified”,这意味着ETag / If-None-Match标头正常工作。

我已经在我的localhost和heroku上用webrick测试了它,使用chrome 45和Safari。

不,我的开发工具没有打开,并且未选中“禁用缓存”。

我也试图删除expires_in方法调用的“,must_revalidate:true”。

我错过了什么?

以下是Chrome中网络的输出: 常规:远程地址:127.0.0.1:3000请求URL: http ://localtest.me:3000 / api / books请求方法:GET状态代码:304未修改

响应标头: 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”服务器: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; 模式=块

请求标题:接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp, / ; q = 0.8 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en ; q = 0.8,fr; q = 0.6,他; q = 0.4 Cache-Control:max-age = 0连接:keep-alive主机:localtest.me:3000 If-None-Match:W /“1f1b2d0b822830bc74e7c47a116205be”升级 – 不安全请求:1个用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_10_3)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 45.0.2454.85 Safari / 537.36

这是ruby代码:

before_action :cache_control, only: [:index, :show] def cache_control expires_in 1.day, public: true, must_revalidate: true end 

好吧,标题很好,它只是一米的浏览器如何处理重新加载按钮或快捷键。

我在这里找到答案: https : //stackoverflow.com/a/16510707/789658

以下是chrome中的发现:

  1. 按地址栏上的Enter键会考虑“max-age”, 并且不会向服务器发送请求。
  2. 重新加载按钮或Cmd + R使用If-Modified-Since向服务器发送请求,如果资源未被修改,将返回304 …
  3. Cmd + Shift + R 服务器发送请求, 甚至没有If-Modified-Since