Ruby on Rails: Clear a cached page

前端 未结 6 1473
野的像风
野的像风 2020-12-07 12:56

I have a RoR application (ruby v1.8.7; rails v2.3.5) that is caching a page in the development environment. This wouldn\'t be so much of an issue, but the cached page\'s

6条回答
  •  长情又很酷
    2020-12-07 13:43

    If you're doing fragment caching, you can manually break the cache by updating your cache key, like so:

    Version #1

    <% cache ['cool_name_for_cache_key', 'v1'] do %>
    

    Version #2

    <% cache ['cool_name_for_cache_key', 'v2'] do %>
    

    Or you can have the cache automatically reset based on the state of a non-static object, such as an ActiveRecord object, like so:

    <% cache @user_object do %>
    

    With this ^ method, any time the user object is updated, the cache will automatically be reset.

提交回复
热议问题