Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird cacheing issues with heroku / memcache and dalli

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

like image 706
Jonathan Avatar asked Oct 11 '22 05:10

Jonathan


2 Answers

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.

like image 53
b-r-o-s Avatar answered Oct 12 '22 18:10

b-r-o-s


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
like image 32
Anand Shah Avatar answered Oct 12 '22 20:10

Anand Shah