If you’ve set your Rails cache to Memcached (for example, by setting
:dalli_store), you may, in some cases, want to model the objects stored in Memcached and interact with them as if they were ActiveRecord objects. To that end, I wrote a module implementing the ActiveModel API:
To use it, create a class, include the module, and override the
cache class method to return
Rails.cache (or another cache store whose API is similar):
class MyModel include MemcacheModel private def self.cache Rails.cache end end
You can now find, create, update, save, delete, and destroy
MyModel objects stored in Memcached just like you do with ActiveRecord objects.