Issues using Russian Doll Caching with Template Inheritance

Deadly 提交于 2019-12-04 14:07:58

The problem here is actually what you suggest yourself in the end: you have to move the cache method into your rendered templates.

This may seem like more code, but this is neccesarry for cache digest to work properly. Furthermore, if your partials (_header.html.erb in application, thing_ones and thing_twos) are different, should the cache key be different as well. This means that you should end up with something like this:

# layouts/application.html.erb
<%= render 'header' %>

# application/_header.html.erb 
<% cache 'application_header' do %>
  ...
<% end %>

# thing_ones/_header.html.erb
<% cache 'thing_ones_header' do %>
  ...
<% end %>

# and thing_twos/_header.html.erb
<% cache 'thing_twos_header' do %>
  ...
<% end %>

Without different cache keys would these caches override each other meaning that if eg. application/_header.html.erb was cached first, then that would be the one that is rendered one ThingOnes and ThingTwos pages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!