Model Cache instead of Controller Cache.

Hi, I've made a model cache for rails, to use when you want to cache model instance methods, rather than controller calls. Does anything similar exist already? Any comments on the implementation?

Since it serializes cached data, it might be good to add the following to environment.rb to get YAML-support for the rails class autoloading mechanism.

-- add to environment.rb # YAML support for class autoloading YAML.add_domain_type("ActiveRecord,2007", "") do |type, val|   klass = type.split(':').last.constantize   YAML.object_maker(klass, val) end

class ActiveRecord::Base   def to_yaml_type     "!ActiveRecord,2007/#{self.class}"   end   def to_yaml_properties # only store the attributes     ['@attributes']   end end

-- model_cache_helper.rb # ModelCache to use on an ActiveRecord class to cache method calls. Example:

Hi. Yes, I get nice performance improvements since some of the model methods takes a few seconds with a disabled cache. Seems like a nice feature when you have database-intensive method calls.

Yes, EDGE seems to have some model caching, but only for a code-block. Instead, these results are cached until you explicitly call expire_cache, just like the cache in a controller.

Tobias,

A tiny detail but if you add

    ActiveRecord::Base.send(:include, ModelCacheHelper)

in environment.rb, you'll no longer have to explicitely include it, and you'd just have to write:

    cache_method :heavy_calculation

Alain Ravet