Heroku生产设置Cache-Control与本地生产不同

时间:2012-10-17 00:45:06

标签: ruby-on-rails heroku ruby-on-rails-3.2 rack http-caching

我在http://chesseng.herokuapp.com/上运行了一个应用程序,当我访问带有chrome的页面并且禁用了缓存时,我得到了application-fingerprint.css的响应头,类似于

Cache-Control:private
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/css
Date:Wed, 17 Oct 2012 00:17:19 GMT
Last-Modified:Tue, 16 Oct 2012 03:13:38 GMT
Status:200 OK
transfer-encoding:chunked
Vary:Accept-Encoding
X-Rack-Cache:miss

但是,如果我使用rails s -e production启动本地实例并访问它,那么application-fingerprint.css的响应头就像是

Age:5119
Cache-Control:public, max-age=31536000
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:95828
Content-Type:application/javascript
Date:Tue, 16 Oct 2012 23:01:27 GMT
Etag:"0bf9e9837d421c2e28be1ef4f0794a48"
Last-Modified:Tue, 16 Oct 2012 01:07:17 GMT
Server:WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Vary:Accept-Encoding
X-Content-Digest:add442e2036c1e6e9f4860dcc44496582a5c91b1
X-Rack-Cache:fresh
X-Request-Id:b89de17e397ac7b60acfe500e8d15df9
X-Runtime:0.001632
X-Ua-Compatible:IE=Edge,chrome=1

为什么缓存相关字段如Cache-Control,Etag与heroku相比如此不同?据推测,我希望heroku返回Cache-Control:public,max-age = 31536000。但我需要先了解为什么在我的本地生产模式中设置Cache-Control:public, max-age=31536000。令人费解的是,如果我在config.static_cache_control = "public, max-age=3600"中设置config/environments/production.rb并在生产中启动本地服务器,它仍会返回max-age=31536000并且似​​乎忽略max-age=3600

1 个答案:

答案 0 :(得分:0)

X-Rack-Cache标题看起来您正在使用会影响缓存标头的rack-cache middleware。由于本地资源位于缓存中(X-Rack-Cache:fresh),但在Heroku上,不是(X-Rack-Cache:miss)可以解释差异。

尝试从中间件堆栈中删除rack-cache,看看差异是否消失。

相关问题