I have a few models that contain static data, and I'm trying to cache them. I've read the various guides and railscasts on caching and thought it would be simple, but still can't figure it out. For example, I have the following model
class ActionType < ActiveRecord::Base
def self.find(id)
Rails.cache.fetch(cache_key) { ActionType.find(id) }
end
end
But this is creating the following errors:
wrong number of arguments (2 for 1)
with the following stacktrace
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/belongs_to_association.rb:49:in `find'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/belongs_to_association.rb:49:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/belongs_to_association.rb:49:in `find_target'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_proxy.rb:240:in `load_target'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_proxy.rb:112:in `reload'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations.rb:1219:in `action_type'
I've recently upgraded to Rails 2.3.3 (from 2.0.1) to take advantage of the caching stuff built into the more recent versions.
Also, fyi, most of these models are simple reference tables with an id and description. However, one has 30 columns and 100+ rows, but is still truly static data that I'd like to cache if possible. All of those 30 columns except one are booleans and small integers (that last one is a short string), so it shouldn't take up too much memory.