2016-04-29 71 views
1

我想我必须在这里丢失的东西如何Collection caching - 1.3.1工作。当我将cached: true属性添加到渲染器时,不会在模型更改时刷新缓存。但是,如果没有此属性,它将按预期工作。Rails 5 - 集合缓存不刷新

attending.html.erb

<%= render partial: 'attending_item', collection: @attendees, locals: {reserved: true}, cached: true %> 

_item_attending.html.erb

<% cache([attendee.user, attendee, reserved]) do %> 
    <li class="attendee_id_<%= attendee.id %> <%= reserved ? 'reserved' : 'confirmed' %>"> 
    <%= image_tag(attendee.user.profile.avatar_url(:avatar), size: '25x25') %> 
    <%= attendee.user.full_name %> 
</li> 
<% end %> 

用户模型将通过touch: true的剖面模型得到更新,所以当他们更新有头像例如:

belongs_to :user, touch: true 

有人可以向我解释我缺少什么或不了解收藏缓存如何工作,也许这是一个错误Rails

回答

0

这里迟到了,但我不认为你的缓存过期了,因为它依赖于用户和保留值。

查看合并到Rails中的multi_fetch_fragments gem的更好文档以增加一些线索。

我想你想改变你的cache: truecache: Proc.new { |attendee| [attendee, user, reserved] }考虑到那里的变化。

此外,我相信你会想要删除_item_attending.html.erb文件中的cache块,因为部分被自动缓存。