Cached Models
cached_models provides to your models a transparent approach to use Rails internal cache mechanism.
Usually, when you decide to use cache for your ActiveRecord results, you have to manually implement complex expiring policies.
cached_models simplifies your code: class Post true
end
class Author true
end
That’s all!!.
A more complex example.. has_many :tickets, :cached => true
has_many :recent_tickets, :limit => 5,
:order => ‘id DESC’, :cached => true
end class Developer true
end
class Project true
Example 1
developer = project.developers.last
developer.update_attributes :first_name => ‘Luca’ # Database update and cache expiration for project cache
project.developers # Database fetch and automatic cache storing
Example 2
developer = project.developers.last
project2.developers
# Fetch associated collection for both the projects
project.developers
project2.developers
Example 3
project.tickets # Database fetch and automatic cache storing
ticket = project.recent_tickets.first
ticket.update_attributes :state => 'solved' # Database update and cache expiration for both tickets and recent_tickets entries
The current version works only with the has_many macro.
How to install
$ ./script/plugin install git://github.com/jodosha/cached_models.git