你将如何设置一个俄罗斯娃娃,如基于密钥的缓存过期与嵌入式文档?如37 个信号所述
我相信touch
是belongs_to
在 Mongoid 3.0 中添加的,但是对于嵌入式文档,您将如何处理它?
示例类:
class House
embeds_many :persons
end
class Person
embedded_in :house
end
看法:
<% cache ['v1', house] do %>
<%= house.some_attribute %>
<% house.persons.each |person| %>
<% cache ['v1' person] do %>
<%= render 'houses/person', person: person %>
<% end %>
<% end %>
<% end %>
概括触摸的最简单方法是什么?所以当我更新一个人时,它嵌入的房子会被触动。
编辑:或者这里的想法是重新渲染所有嵌入式项目相对便宜?当然我可以这样做:
class Person
after_save :touch_house
def touch_house
house.touch
end
end