Rails - 片段缓存不会过期
这个把我难住了。
我有一个带有缓存片段的视图:
- cache :key=>"news" do
%h2 News
- etc
我有一个使用的清理器:
def expire_home_cache
puts "expire_home_cache"
expire_fragment(:key => "news")
end
调用清理器是因为我可以在控制台输出中看到“expire_home_cache”。
但片段没有更新......
有什么想法吗?
This one has me stumped.
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
The sweeper is called as I can see "expire_home_cache" in the console output.
But the fragment is not updated ...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试将
expire_fragment(:key => "news")
替换为ActionController::Base.new.expire_fragment(:key => "news")
没有时间解释,但这对我有用。
Try replacing
expire_fragment(:key => "news")
withActionController::Base.new.expire_fragment(:key => "news")
No time to explain, but it worked for me.
你可以尝试这个:
并且...
...或者尝试这个...
我认为问题可能是ruby或rails很难确定密钥到底是什么,因此缓存方法和expire_fragment正在生成两个不同的缓存键。
You might try this:
and...
...or try this ...
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.
正确的方法是:
然后在你的扫地机中:
The proper way to do this is:
And then in your sweeper:
这并不能直接回答您的问题,但是您是否尝试过使用 timed_fragment_cache 插件作为替代方案?
http://github.com/tricycle/timed_fragment_cache/tree/master
我发现了这个这是使我的项目中的片段过期的更简单的方法。
This doesn't directly answer your question, but have you tried the timed_fragment_cache plugin as an alternative?
http://github.com/tricycle/timed_fragment_cache/tree/master
I found this to be a much simpler way of expiring fragments in my projects.