Plugins - method_cache

StarAdd to favorites

MethodCache
===========

A Rails (v2.1.0) plugin that tries to solve the problem of having to call a method repetitively. That method is
expensive to be recalculated everytime.
The solution is to cache the method results and we've always done that by caching a method's result in instance
variables.

method_cache plugin frees you from the trouble of worrying about writing caching code and introduces a couple of utility
methods
in ActiveRecord objects that make your life easier.

In its current form, the plugin provides the following extensions to ActiveRecord Objects

caches_method :method_name
caches_class_method :method_name
and for expiring the cache
instance.expire_method :method_name
Class.expire_instance_method :method_name, id
Class.expire_class_method :method_name

Introducing the plugin blog entry
=================================
http://humanzz.spaces.live.com/blog/cns!82322F9506CB0449!713.entry

Setup
=====

ruby script/plugin install git://github.com/humanzz/method_cache.git


Examples
========
class User < ActiveRecord::Base
def costy_method
#some real heavy calculation that takes alot of resources
#to complete
#this method is called regularly and its results rarely change
end
caches_method :costy_method
end

humanzz

git://github.com/humanzz/method_cache.git

Rails' (MIT)

  • Currently 5.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment
Eric Anderson 9 Jul 2008

Doesn't Rails have something like this built in (except that it also allows the method to have arguments). I think the cache becomes a hash where the arguments are the key to the hash. I think it is used internal to Rails a good bit but haven't seem much use of it outside of Rails.

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?