active record context, , , , , , , " />

Introducing … Static Record Cache plugin

March 31, 2009

Static Record Cache permanently caches ActiveRecord data for classes which contain small amounts of static data (data that rarely changes). In addition to caching queries on Ids, methods like find_by_name will use cache hits rather than new queries to retrieve data. Static Record Cache is designed to work with or without the built inĀ  query cache, but by contrast permanently stores the actual record across all contexts and avoids the overhead of instantiating new ActiveRecord objects.


script/plugin install git://


class SomeStaticClass < ActiveRecord::Base

#cache hits
SomeStaticClass.find :all

One can specify the cache key for faster lookups and also customize the finder SQL for the class. More documentation can be found in the rdocs.

Another, simpler method of caching can be used by folks using the active record context plugin by technoweenie. Extending StaticRecordCache will permanently cache data for the class regardless of context. This however, only caches by id.

class TelephoneCarriers < ActiveRecord::Base
  extend StaticActiveRecordContext

Be sure to install active_record_cache plugin:

script/plugin install

Leave a Reply