Virtual Attribute Cache

The ultimate way to cache Active Record virtual attributes.

Installation

As a RubyGem:

gem install thisisdato-va_cache

As a Rails plugin:

script/plugin install git://github.com/thisisdato/va_cache.git

Usage

Virtual Attribute Cache extends Active Record with a cached_virtual_attribute method for you to use in your models. Provide the name of the virtual attribute to be cached and a proc, symbol, or string indicating when to expire the cache:

cached_virtual_attribute :full_name, :expire_if => { |p| p.first_name_changed? || p.last_name_changed? }

All you need is a column of the same name as the virtual attribute. In the following case, if body_textile_changed? returns true, the cache will be expired:

cached_virtual_attribute :body, :expire_if => :body_textile_changed

Note: Virtual Attribute Cache will suffix the question mark (?) automatically.

Copyright © 2009 David Trasbo. Virtual Attribute Cache is released under the terms of the MIT License. See LICENSE.txt for further details.