Rails-片段缓存未到期 [英] Rails - fragment cache not expiring

查看:93
本文介绍了Rails-片段缓存未到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个让我难过。

我有一个带有缓存片段的视图:

I have a view with a cached fragment:

 - cache :key=>"news" do    
   %h2 News
   - etc

我有一个使用的清扫程序:

I have a sweeper that uses:

def expire_home_cache
  puts "expire_home_cache"
  expire_fragment(:key => "news") 
end

可以在控制台输出中看到 expire_home_cache。

The sweeper is called as I can see "expire_home_cache" in the console output.

但是该片段未更新...

But the fragment is not updated ...

有什么想法吗?

推荐答案

您可以尝试以下方法:

   cache("news") do    
     %h2 News
     - etc
   end

和...

def expire_home_cache
  puts "expire_home_cache"
  expire_fragment("news") 
end

。 .or试试这个...

...or try this ...

 - cache({:key=>"news"}) do    
   %h2 News
   - etc

我认为问题可能是红宝石或Rails很难确定确切的密钥,因此cache方法和expire_fragment正在生成两个不同的缓存密钥。

I am thinking the issue may be that ruby or rails is having a hard time determining what the key is exactly and so the cache method and expire_fragment are generating two different cache keys.

这篇关于Rails-片段缓存未到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆