18

就像是

Rails.cache.delete('site_search_form')

似乎不起作用。这可能吗?谢谢。

4

4 回答 4

55

ActionController::Base.new.expire_fragment(key)

于 2009-05-08T05:12:44.873 回答
6

缓存片段条目的创建键与您使用 Rails.cache 访问的键稍有不同。

改为使用expire_fragment(您可以将其发送到控制器):http ://api.rubyonrails.org/classes/ActionController/Caching/Fragments.html#M000438

于 2009-04-16T16:44:04.847 回答
2
Rails.cache.delete "views/site_search_form"
于 2014-06-14T14:45:25.530 回答
0

在 Rails 5 中,我采取了以下步骤来破坏缓存,而无需使用skip_digest: true. 我们的问题是更改 I18n 字符串的值不会反映在计算的缓存摘要中,因此缓存不会自动被破坏。

这是定义缓存块的视图:

/ views/layouts/_footer.html.slim
- cache :footer do
  span= t('shared.footer')

然后在rails控制台中我运行:

fragment = ActionController::Base.new.view_context.cache_fragment_name(:footer, virtual_path: 'layouts/_footer.html.slim')
ActionController::Base.new.expire_fragment(fragment)

cache_fragment_name将根据virtual_path关键字参数计算出摘要。

于 2017-05-26T17:24:56.067 回答