Storing Tables in Memory

Is there a was to specify to Rails that it should hold the contents of
a table in memory?

For instances, I have a lookup table that is a two column table (id and
description) and then lots of things that belong_to those its.

class A < ActiveRecord::Base

   belongs_to :lookup

end

I'd love to able to say a.lookup.description without needing another
SQL call. I know you can avoid the call using the :include feature, but
that means joins in the SQL backend, and I'm doing LOTS of these
queries.

Something like this would be great:

class Lookup < ActiveRecord::Base

   :cache_table_in_memory

end

Then all operations on the Lookup class would be done in memory. It
would also add a refresh method that you could manually call on the
infrequent event where the lookup table changes.

If something like this exists, can someone point me in the right
direction? If not, consider it a feature suggestion.

Thanks,

Andrew

Andrew Selder wrote:

Is there a was to specify to Rails that it should hold the contents of
a table in memory?

For instances, I have a lookup table that is a two column table (id and
description) and then lots of things that belong_to those its.

class A < ActiveRecord::Base

  belongs_to :lookup

end

I'd love to able to say a.lookup.description without needing another
SQL call. I know you can avoid the call using the :include feature, but
that means joins in the SQL backend, and I'm doing LOTS of these
queries.

Something like this would be great:

class Lookup < ActiveRecord::Base

  :cache_table_in_memory

end

Then all operations on the Lookup class would be done in memory. It
would also add a refresh method that you could manually call on the
infrequent event where the lookup table changes.

If something like this exists, can someone point me in the right
direction? If not, consider it a feature suggestion.

Thanks,

Andrew

I hope you are aware of cached_model plugin on top of memcached by honourable drbrain aka Eric Hodel of Holy School of Seattle.rb.

Now, of course, you can't use the above plugin, if you are not running memcached. Still, quite a few DRb based caching mechanisms are sprouting all over the place.

You can use, Bakcgroundrb to cache values or else you can use this: http://boogaloo.rubyforge.org/doc/

Or if you are unhappy with all the above shit, roll your own and have your name embodied in golden chapters of rails development forever.

Have a look at Trevor Squires enumerations mixin which allows you to
treat instances of your ActiveRecord models as though they were an
enumeration of values while caching Instances in memory.

http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk/