Hi,
class User < ActiveRecord::Base
def self.get_cache(id)
Rails.cache.fetch(“users/#{id}”) { find(id) }
end
end
Accesing a cached model object immediately after caching works as
expected:
User.get_cache(1).cache_key # => OK
But once I try to do the same from another action it’s not possible
anymore.
I get an error message “stack level too deep”.
User.get_cache(1).cache)key # =>
SystemStackError (stack level too deep):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/attribute_methods.rb:64:in generated_methods?' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/attribute_methods.rb:237:in
method_missing’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/attribute_methods.rb:245:in method_missing' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/base.rb:2167:in
cache_key’
/app/controllers/users_controller.rb:5:in index' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/ action_controller/base.rb:1162:in
send’
What am I doing or thinking wrong?