Best practices for using memcached in Rails?
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2009-05-09T07:36:27Z
Indexed on
2010/05/04
17:38 UTC
Read the original article
Hit count: 336
Hello everybody,
as database transcations in our app are getting more and more time consuming, we have started to use memcached to reduce the amount of queries passed to MySQL.
All in all, it works fine and really saves a lot of time.
But as caching was "silently appearing" as a workaround to give the app more juice, a lot of our models now contain code like this:
def self.all_cached
Rails.cache.fetch('object_name') {
find(
:all,
:include => [associations])
}
end
This is getting more and more a pain as filling and flushing the cache happens in several classes accross the application.
Now, I was wondering if there was a better way to abstract memcached logic to make it more powerful and easy to use across all needed models?
I was thinking about having some kind of memcached-module which is included in all needed modules.
But before playing around, I thought: Let's ask experts first :-)
Thanks
Matt
© Stack Overflow or respective owner