Rails-如何刷新部分缓存中的项目?

时间:2019-06-14 07:39:50

标签: ruby-on-rails caching

我遇到这种情况(主视图模板):

<% 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>

在这部分内容中,属性something1something2始终保持不变,但是属性something3的变化很大(一天几次)。

这是怎么回事-当我们的一位管理员更改属性something3时,通常不会立即“刷新”主视图模板,而我们看到的是“旧”值。发生更改时,如何强制Rails缓存立即刷新?

1 个答案:

答案 0 :(得分:-1)

使用缓存键,当您更新任何内容时,缓存键将被更新,您的数据也将被更新。

相关问题