Skip to content

Instantly share code, notes, and snippets.

@sapienza
Created July 12, 2013 19:23
Show Gist options
  • Select an option

  • Save sapienza/5987040 to your computer and use it in GitHub Desktop.

Select an option

Save sapienza/5987040 to your computer and use it in GitHub Desktop.
Rails and Memcache with Dalli. How to refresh the cache just after updating or destroying it (force)
class Contact < ActiveRecord::Base
after_save :expire_contact_all_cache
after_destroy :expire_contact_all_cache
def self.all_cached
Rails.cache.fetch('Contact.all') { all }
end
def expire_contact_all_cache
Rails.cache.fetch('Contact.all', :force => true) do
results = Contact.all
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment