网站分析器说我没有激活页面缓存,https://tools.pingdom.com/#!/bDj23F/www.anthonygalli.com .不过,我还是按照我能动手的每一步去做。我正在使用 rails "4.2.7.1"
在 View 中
<%= render :partial => @posts, cached: true %>
在 Controller 中
fresh_when last_modified: @posts.created_at.utc, etag: @posts
生产中.rb
config.action_controller.perform_caching = true
config.action_controller.asset_host = 'd37p52igaahgm9.cloudfront.net'
更新
最佳答案
您可以在云端分配中做的一件事是添加一个自定义 header 参数。在这里,Google和 Amazon不完全同意,因为谷歌推荐使用Expires
header,亚马逊推荐使用Cache-Control max-age
参数/值,所以你必须选择一个,因为亚马逊会如果指定了两者,则仅处理 Cache-Control
We recommend that you use the Cache-Control max-age directive instead of the Expires header field to control object caching. If you specify values both for Cache-Control max-age and for Expires, CloudFront uses only the value of Cache-Control max-age.
如果您的云端分配来自 S3 存储桶,您可以 Add Headers to Your Objects Using the Amazon S3 Console
- 从 aws s3 控制台打开 s3 对象的属性
- 在右 Pane 中,展开元数据。
- 点击添加更多元数据。
- 在 key 列表中,单击缓存控制或过期(视情况而定)。
在“值”字段中,输入适用的值:
对于缓存控制字段,输入:
max-age=number of seconds that you want objects to stay in a CloudFront edge cache
对于“过期”字段,以 HTML 格式输入日期和时间。
- 点击保存。
见下文
关于ruby-on-rails - 如何使用 Heroku 和 Cloudfront 为 Rails 激活页面缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39588396/