Skip to content


Subversion checkout URL

You can clone with
Download ZIP
CachedModels provides to your ActiveRecord objects a transparent approach to use ActiveSupport caching mechanism.
Tree: 66b602b0f3
Failed to load latest commit information.
lib Rails 2.3.3 compat [Gregg Kellogg]
tasks Make test suite work with Rails 2.3.0
.gitignore Make test suite work with Rails 2.3.0
CHANGELOG Use Use valid_keys_for_has_and_belongs_to_many_association
MIT-LICENSE has_many association support
README Make sure of use Memcached as test store. Compatibility changes for A…
Rakefile Tagged v0.0.3
about.yml Tagged v0.0.3
cached-models.gemspec Tagged v0.0.3
init.rb Made independent of Rails
install.rb has_many association support
setup.rb Added gem related files
uninstall.rb has_many association support


= CachedModels

CachedModels provides to your models a transparent approach to use Rails internal caching mechanism.

Check for news and tutorials at the {project home page}[].

= Usage

Using Memcached and Rails 2.2.0

Make sure to configure your current environment with:

config.cache_classes = true
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store

class Project < ActiveRecord::Base
  has_many :developers, :cached => true
  has_many :tickets, :cached => true
  has_many :recent_tickets, :limit => 5,
    :order => 'id DESC', :cached => true

class Developer < ActiveRecord::Base
  belongs_to :project, :cached => true

Example 1
  project.developers # Database fetch and automatic cache storing

  developer = project.developers.last
  developer.update_attributes :first_name => 'Luca' # Database update and cache expiration for project cache

Example 2
  project2.developers # Database fetch and automatic cache storing
  project2.developers << developer # Database update and cache renewal for both project and project2 caches

Example 3 # 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

= Install

There are three ways to install CachedModels

Gemified plugin:

  environment.rb do |config|
      config.gem 'cached-models'

  $ (sudo) rake gems:install
  $ rake gems:unpack

Rails plugin:

  $ ./script/plugin install git://


  $ (sudo) gem install cached-models
  in your project:
    require 'rubygems'
    require 'activerecord'
    require 'cached-models'

    ActiveRecord::Base.rails_cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, 'localhost')

= Test
  Make sure your current store is Memcached

= Contribute

* Check out the code and test it:
  $ git clone git://
  $ rake cached_models

* Create a ticket to the {Sushistar Lighthouse page}[]

* Create a patch and add as attachment to the ticket.

Copyright (c) 2008 Luca Guidi, released under the MIT license
Something went wrong with that request. Please try again.