0

i want to cache my model objects in low level ( aka low level caching ) and I am doing this by memcached and dalli. i overloaded the find method in FOO class :

def self.find(id)
  Rails.cache.fetch('users/' , id) do
    User.find(id)
  end
end

the only problem here is about user updates. i want to expire that cache whenever the user is updated but i didn't find something like Rails.cache.expire(key). is there any suitable to do this?

Pooya
  • 992
  • 2
  • 10
  • 31
  • 1
    it seems like you are trying to replace the `db` with cache, not sure if that is a good idea. That said you can expire a key by calling `Rails.cache.delete(key)` – tihom Sep 21 '13 at 22:02
  • Definitely *not* a good idea - Rails already handles caching models pretty well, so even if you get this working, it's still probably not going to be an improvement. – MrTheWalrus Sep 23 '13 at 01:41

0 Answers0