2011-08-19 69 views
5

请考虑以下情况。从我的heroku控制台:heroku/memcache和dalli的奇怪缓存问题

>> Rails.cache.stats 
=> {"server_id"=>{"evictions"=>"0", "curr_items"=>"2064", "total_items"=>"18793", "bytes"=>"7674501", ... 
>> Rails.cache.clear 
=> [true] 
>> Rails.cache.stats 
=> {"server_id"=>{"evictions"=>"0", "curr_items"=>"2064", "total_items"=>"18793", "bytes"=>"7674501", 

超级奇怪 - 我怎么能清除我的缓存!


相似的问题? :https://stackoverflow.com/q/7122513/192791

+0

您是否试过Rails.cache.read('key')',您知道存储在该缓存中的值是该特定键的值。由于@ b-r-o-s提到的统计信息并不总是立即更新,但是如果你尝试从缓存中读取数据,那么它应该立即返回零。 –

+0

我正在面对类似的东西,我运行Rails.cache.clear,如果我想要重新加载缓存,我必须重新启动我的实例。奇怪的。 – chischaschos

回答

3

如果通过控制台直接连接到达利/ memcahced客户端和flush_all缓存清除。

dc = Dalli::Client.new('localhost:11211') 
dc.flush_all 

注:统计数据需要一段时间才能更新,但缓存肯定会清楚。

+0

请注意,'ActiveSupport :: Cache :: DalliStore'在运行'clear'时使用了flush_all,请参阅这里的文档:http://rubydoc.info /gems/dalli/1.0.5/ActiveSupport/Cache/DalliStore –

1

到期缓存部分在http://devcenter.heroku.com/articles/building-a-rails-3-application-with-the-memcache-addon建议使用过滤器

after_save :expire_contact_all_cache 
after_destroy :expire_contact_all_cache 

def expire_contact_all_cache 
    Rails.cache.delete('Contact.all') 
end 
+1

虽然这不适用于视图中的碎片,但 - 是吗? – Slick23

+0

感谢您 - 我不是在寻找过期的缓存策略 - 我想知道为什么Rails.cache.clear没有清除缓存。 (当我发布一个新版本 - 我想完全清除缓存) – Jonathan