Rails 2.1 cache problem


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?

take a look at: Can't models be cached in development env? - Rails - Ruby-Forum

you enable class caching changing "config.cache_classes" to true in your config/development.rb file.

It's look like a bug to reload environment each time after code edit.. Any other ideas?

Thanks for the response.

Any update on this caching bug? It's driving me crazy. Please, post a solution if you've figured this out, or know of a resource that will help me understand it better. Thanks.

(from http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/c74a74df959c56ee)

These seem to be related:

http://dev.rubyonrails.org/ticket/10896 http://dev.rubyonrails.org/ticket/10722


But I still haven't seen a definitive solution.