7

我将生产服务器上的标头检查为

    curl --head -H "Accept-Encoding: gzip" http://foo.heroku.com/assets/mobile.js

并且我返回以下标头,这些标头表明 RAILS 没有设置缓存控制标头。

HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Wed, 22 Jun 2011 12:01:55 GMT
Content-Type: application/javascript
Connection: keep-alive
Content-Md5: efb90436a465f8a73efb467109f745f3
Cache-Control: no-cache
Last-Modified: Wed, 22 Jun 2011 11:46:04 GMT
Etag: "efb90436a465f8a73efb467109f745f3"
X-Ua-Compatible: IE=Edge,chrome=1
X-Runtime: 0.001258
X-Content-Digest: 6493f457e9550773761bb1c2c52ec4cb44a19c19
X-Rack-Cache: stale, valid, store
X-Varnish: 164373614
Age: 0
Via: 1.1 varnish
Content-Encoding: gzip

我想让 heroku 的清漆缓存缓存资产,并且只在 git push 上刷新。关于如何获得这个的任何想法?

布拉德

4

2 回答 2

9

你必须在你的 environment/production.rb 中添加这个:

config.serve_static_assets = true
config.static_cache_control = "public, max-age=172800"
于 2012-02-25T11:46:33.813 回答
1

Camille 的回答对于 5.1 之前的 Rails 版本是正确的

但是,在 Rails 5.1 config.static_cache_control中将被弃用。使用新的可用选项更新的代码应该是:

config.serve_static_assets = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age= 172800' }
于 2016-07-27T21:33:07.243 回答