On Aug 19, 2006, at 11:00 AM, Paul wrote:

> I am coming from a Smalltalk background and we
> would typically cache code/description lookup table rows into a class
> variable for performance. That is, when we wanted to look up a
> description we would check the cache first and then hit the database
> only if it had not been retrieved yet.

This smells like premature optimization to me.  You've timed it and  
it's too slow or you have users complaining about the speed?  If not,  
I worry you might be complicating this before you need to.

You are right that in this case, it shouldn't hurt to use a class  
variable.  It is a waste of memory though and you may not get great  
cache hit rates.

The right way to handle this is with Rails's cache support:

   http://api.rubyonrails.com/classes/ActionController/Caching.html

This should be faster and more natural to implement, since you can  
develop normally and then apply caching as needed.  It will also work  
across interpreters.

I'm not trying to tell you how to run your site.  I hope it doesn't  
sound like I am.  I'm just trying to help you avoid choices I'm  
pretty sure you will regret down the road.

Best of luck with your site.

James Edward Gray II