【发布时间】:2014-06-05 18:44:56
【问题描述】:
我正在关注“使用 Rails 4 进行敏捷 Web 开发”指南,并来到了关于缓存的部分。以下是要遵循的步骤:
-
在 config/environments/development.rb 中
config.action_controller.perform_caching = true -
在 app/models/product.rb 中
def self.latest Product.order(:updated_at).last end -
在views/store/index.html.erb中
<% cache ['store', Product.latest] do %> <% @products.each do |product| %> <% cache ['entry', product] do %> <div class="entry"> <%= image_tag(product.image_url) %> <h3><%= product.title %></h3> <%= sanitize(product.description) %> <div class="price_line"> <span class="price"><%= number_to_currency(product.price) %></span> </div> </div> <% end %> <% end %> <% end %>
为了验证现金是否有效,这本书说:“就验证这是否有效,遗憾的是没有太多可看的。如果你去那个页面,你应该看不到任何变化,这实际上是点!您可以做的最好的事情是在缓存块内的任何位置更改模板,而不更新任何产品,并验证您没有看到该更新,因为页面的缓存版本尚未更新”。
但是,当我尝试在缓存块内的代码中添加“Hello”字符串时,它会出现在页面上。我已经完成了所有服务器的重新启动,什么都没有。
但是,当我在本地主机上重新加载页面时,我确实看到了这一行
Cache digest for app/views/store/index.html.erb: 6c620ede1d4e824439a7b0e3b177620f
当我有的时候不是他们的 config.action_controller.perform_caching = false
git hub 仓库链接:https://github.com/BrianLobdell/depot
谢谢, 布赖恩
【问题讨论】:
-
那又怎样?一切似乎都正常......
-
书中的测试方法是在缓存块中添加一些不修改产品的内容(如“hello”字符串),如果缓存正在工作,它就不会显示这页纸。但是,就我而言,“Hello”字符串确实出现了
标签: ruby-on-rails ruby caching ruby-on-rails-4