I'm looking for a ruby gem (or rails plugin) which abstracts the details of memcached in the same way that ActiveRecord abstracts the details of SQL. I am NOT looking for something to help cache ActiveRecord models in memcached. I'm sure there are approximately 4215 gems that will help with that problem.
Ideally what I'd like is to be able to do something like:
class Apple < MemcachedModel # whatever else here end
and then be able to do stuff like:
my_apple = Apple.find('some memcached key')
which would look up the JSON representation of this class in memcached and deserialize it. I'd also maybe be able to do things like:
my_apple.color = "red" # persist changes back to memcached my_apple.save # load any changes from memcached into local model my_apple.update
It seems like someone must have scratched this itch by now and created something along these lines, but whenever I google for such a gem I just keep turning up thing which help cache AR models using memcached.
You can take a look at my
monetagem, which is an ORM'ish thing for all kinds of key-value-stores. You can see it at: http://github.com/wycats/moneta/tree/master
The basic idea behind moneta is that all KVSs should behave exactly like a subset of normal Ruby hashes. We support:
update_keymethods take an additional options hash which you can use thusly:
We support a large number of KVSs:
Every store supports expiry, either natively (like in memcached) or using a standard module that emulates memcache-style expiry. The API is always identical and there is a shared spec that all adapters are run against to ensure compliance.
It is also quite easy to add your own adapter, which is why so many exist.