我遇到这种情况(主视图模板):
<% if @cars.count(:all) > 0 %>
<% presenter.collection.each_pair do |date, collection| %>
<tr>
<td>
...
</td>
</tr>
<%= render partial: 'car_row_content', collection: collection, as: :car, cached: Proc.new{|car| [cache_prefix, acl_fingerprint, car.record] } %>
<% end %>
<% end %>
以下是部分car_row_content
的样子:
<tr>
<td>
<%= car.something1 %>
</td>
<td>
<%= car.something2 %>
</td>
<td>
<%= car.something3 %>
</td>
</tr>
在这部分内容中,属性something1
和something2
始终保持不变,但是属性something3
的变化很大(一天几次)。
这是怎么回事-当我们的一位管理员更改属性something3
时,通常不会立即“刷新”主视图模板,而我们看到的是“旧”值。发生更改时,如何强制Rails缓存立即刷新?
答案 0 :(得分:-1)
使用缓存键,当您更新任何内容时,缓存键将被更新,您的数据也将被更新。