就像
Rails.cache.delete('site_search_form')
好像不管用。这可能吗?谢谢
vcirk6k61#
ActionController::Base.new.expire_fragment(key)
quhf5bfb2#
创建缓存片段条目时使用的键与使用Rails.cache访问的键略有不同。使用expire_fragment代替(您可以将其发送到控制器):http://api.rubyonrails.org/classes/ActionController/Caching/Fragments.html#M000438
expire_fragment
uemypmqf3#
Rails.cache.delete "views/site_search_form"
d8tt03nd4#
在Rails5中,我采取了以下步骤来破坏该高速缓存,而没有求助于skip_digest: true。我们的问题是,改变I18n字符串的值不会反映在计算的缓存摘要中,因此该高速缓存不会自动被破坏。以下是定义该高速缓存块的视图:
skip_digest: true
/ 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关键字参数计算出摘要。
cache_fragment_name
virtual_path
kninwzqo5#
另一种选择,如果你使用Redis作为缓存存储,是直接使用keys方法从redis中搜索和删除。
keys
# get direct Redis client from Rails cache store redis = Rails.cache.redis # search for your key keys = redis.keys.grep(/site_search_form/) # delete the keys keys.each do |key| redis.del(key) end
5条答案
按热度按时间vcirk6k61#
ActionController::Base.new.expire_fragment(key)
quhf5bfb2#
创建缓存片段条目时使用的键与使用Rails.cache访问的键略有不同。
使用
expire_fragment
代替(您可以将其发送到控制器):http://api.rubyonrails.org/classes/ActionController/Caching/Fragments.html#M000438uemypmqf3#
d8tt03nd4#
在Rails5中,我采取了以下步骤来破坏该高速缓存,而没有求助于
skip_digest: true
。我们的问题是,改变I18n字符串的值不会反映在计算的缓存摘要中,因此该高速缓存不会自动被破坏。以下是定义该高速缓存块的视图:
然后在rails控制台中运行:
cache_fragment_name
将根据virtual_path
关键字参数计算出摘要。kninwzqo5#
另一种选择,如果你使用Redis作为缓存存储,是直接使用
keys
方法从redis中搜索和删除。