Panasonic Youth rob sanheim writes about software, business, ruby, music, stuff and things



Posted
17 August 2006 @ 8pm

Tagged
Object Oriented, Rails, Ruby

Discuss

Memcached, Rails, and You

Geoffrey continues the run of helpful articles with an intro of how to implement memcached with ActiveRecord. I know my team will have to look into this soon, as we have some model objects that are essentially lookup objects, but need to be used for every request in some way. Since they change rarely, we should just be able to load them once a day and let them sit in memory.

Robot Coop’s cached-model looks like it would help for this, but I don’t understand why its implemented as a class instead of a module? Seems like caching should be an implementation detail, so a module would be perfect. Once you use cached-model you are stuck with that inheritance, and now you have to hack your way around it if you want to use some sort of common abstract class. I feel the same way about the using a base class like “AlternateDatabase” to enable multiple database connectivity, but sometimes quick and easy wins out over the “right way”


3 Comments

Posted by
Chris
20 August 2006 @ 12am

I agree with you on both these points. Where I work, we have all our models inherit from ActiveRecord::Base and that’s that. For the multi-db problem, we’ve rolled a plugin we call named_connections (”uses_connection :user_db” in all the models which use the user db, for instance). For memcached we’ve rolled our own acts_as_cached plugin which I will be giving a presentation on (as well as other memcached tips) at the September San Francisco Ruby meetup. My main problem with CachedModel, aside from forcing you to inherit, is that it only allows you to cache single, non-associated ActiveRecord objects. We’ve felt the need to do more (without repeating code over and over) and acts_as_cached addresses this. Maybe you can have a look when it’s out? I’d love feedback.


Posted by
Rob
21 August 2006 @ 9am

That sounds great, Chris. I’d love to take a look at it, and may integrate it into our stuff once its available. I’ll be watching your feed for an announcement on it.


Posted by
Eric Hodel
23 August 2006 @ 12pm

Here’s why we use subclassing instead of include for CachedModel.


Leave a Comment

More on Java/Ruby Communities, or Chill Out: Its Just Code Dude Why Can’t I Show Line Numbers in “View Source” in Firefox