我已成功设置AWS Cloudfront(我认为)。通过成功,我的意思是我从云端获取东西。
我注意到浏览器没有缓存任何内容,而且所有内容都是重载的。
我将config.static_cache_control = "public, max-age=#{1.year.to_i}"
添加到production.rb
但没有帮助
我正在使用Heroku,Rails 4.0.4,paperclip和asset_sync
我是否错过了配置中的任何内容?或者出了什么问题?
这是请求标题
GET /users/avatars/me.jpg HTTP/1.1
Host: assets.mydomain.net
Connection: keep-alive
Cache-Control: no-cache
Accept: image/webp,*/*;q=0.8
Pragma: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
DNT: 1
Referer: http://mydomain.com
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,he;q=0.6
和回复标题
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 18394
Connection: keep-alive
Date: Thu, 24 Apr 2014 14:16:40 GMT
Last-Modified: Sun, 09 Mar 2014 21:17:09 GMT
ETag: "a81f57bc65cea2535w75aa94c334d"
Accept-Ranges: bytes
Server: AmazonS3
Age: 2157
X-Cache: Hit from cloudfront
Via: 1.1 96cb60390320349823485f0fb38.cloudfront.net (CloudFront)
X-Amz-Cf-Id: gceHbzsluASDFvraASFvalerhgy_GY3nP0Qaa7iPY1ug==
和资产
请求:
Accept:text/css,*/*;q=0.1
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,he;q=0.6
Cache-Control:no-cache
Connection:keep-alive
DNT:1
Host:d36kdk9v8wr6hu.cloudfront.net
Pragma:no-cache
Referer:http://mydomain.com
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
响应标题
Accept-Ranges:bytes
Age:2315
Cache-Control:public, max-age=31557600
Connection:keep-alive
Content-Encoding:gzip
Content-Length:34412
Content-Type:text/css
Date:Thu, 24 Apr 2014 14:16:40 GMT
ETag:"795ae17b75612313b5ce5ecf1a14cd8"
Expires:Fri, 24 Apr 2015 20:12:58 GMT
Last-Modified:Thu, 24 Apr 2014 14:12:59 GMT
Server:AmazonS3
Via:1.1 96cb60390320349823485f0fb38.cloudfront.net (CloudFront)
X-Amz-Cf-Id:SkbZJTSD5PAPnawlerszlsdfnzIOqJROA4LegMgBIPcU1aN0T08sdUA==
X-Cache:Hit from cloudfront
答案 0 :(得分:0)
这对我有用。打开作为CloudFront分配源的S3存储桶,找到要缓存的文件。然后在Properties>下元数据设置一个Cache-Control键,其中包含max-age = x的值。
希望这有帮助!