我正在跟隨'帶有Rails 4的敏捷Web開發指南'指南,並且談到了關於緩存的部分。下面是要遵循的步驟:如何判斷緩存是否正常工作。 Rails 4
- 在配置/環境/ development.rb
config.action_controller.perform_caching = true
在應用程序/模型/ product.rb
def self.latest Product.order(:updated_at).last end
- 的意見
/存儲/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.pe rform_caching =假
鏈接到git的樞紐回購:改變文件的時候,所以它更容易操縱,而不是緩存https://github.com/BrianLobdell/depot
謝謝你,布萊恩
那又如何?一切似乎工作...... – joni
在本書中測試的方式表示,將某些東西添加到未修改產品的緩存塊中(如「hello」字符串),並且如果緩存正在工作,則不會顯示這一頁。但是,在我的情況下,「Hello」字符串確實出現 – megacanyon