Weird cacheing issues with heroku / memcache and dalli

给你一囗甜甜゛ 提交于 2019-12-22 07:08:54

问题


Consider the following. From my heroku console:

>> 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",

Super weird -- how can I clear my cache!!


Similar Issue ? : https://stackoverflow.com/q/7122513/192791


回答1:


If you connect directly to the Dalli/memcahced client through the console and flush_all the cache clears.

i.e.

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

NOTE: the stats take a while to update, but the cache will definitely clear.




回答2:


The Expiring Cache section at http://devcenter.heroku.com/articles/building-a-rails-3-application-with-the-memcache-addon suggests using filters

after_save    :expire_contact_all_cache
after_destroy :expire_contact_all_cache

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


来源:https://stackoverflow.com/questions/7122962/weird-cacheing-issues-with-heroku-memcache-and-dalli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!