Created
July 12, 2013 19:23
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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