【问题标题】:Rails collection render cache doesn't work when I use cached: true当我使用缓存时,Rails 集合渲染缓存不起作用:true
【发布时间】:2018-09-08 22:52:02
【问题描述】:

我的项目使用的是 Rails 4.2.9。

我发现缓存在索引页面中不起作用。 (我检查了日志。)

# This doens't cache.
<%= render partial: 'docs/doc', collection: @docs, cached: true %>

# This caches fine.
<% @docs.each do |doc| %>
  <% cache doc do %>
    <%= render 'docs/doc', doc: doc %>
  <% end %>
<% end %>

根据rails guide,第一个示例不仅有效而且更好。我做错了什么?

【问题讨论】:

标签: ruby-on-rails caching


【解决方案1】:

看来您需要将您的 rails 版本更新到至少版本 5,才能正常工作。

它看起来像version 5 has this feature,但是version 4.2 does not have this feature。它是在this commit 中添加的,您可以在https://blog.bigbinary.com/2016/03/09/rails-5-makes-partial-redering-from-cache-substantially-faster.html 阅读更多相关信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 2016-07-20
    • 2015-08-24
    相关资源
    最近更新 更多