This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Run the following if you haven't already:
gem sources -a http://gems.github.com
Install the gem(s):
sudo gem install jodosha-cached-models
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Mon Feb 16 07:49:02 -0800 2009 | |
| |
CHANGELOG | Mon Feb 16 07:52:23 -0800 2009 | |
| |
MIT-LICENSE | Wed Aug 13 02:33:32 -0700 2008 | |
| |
README | Thu Oct 30 03:57:47 -0700 2008 | |
| |
Rakefile | Wed Oct 22 01:37:42 -0700 2008 | |
| |
about.yml | Wed Oct 22 01:37:42 -0700 2008 | |
| |
cached-models.gemspec | Wed Oct 22 01:37:42 -0700 2008 | |
| |
init.rb | Mon Oct 06 02:47:57 -0700 2008 | |
| |
install.rb | Wed Aug 13 02:33:32 -0700 2008 | |
| |
lib/ | Mon Feb 16 07:52:23 -0800 2009 | |
| |
setup.rb | Fri Oct 10 02:05:00 -0700 2008 | |
| |
tasks/ | Mon Feb 16 07:49:02 -0800 2009 | |
| |
test/ | Mon Feb 16 07:49:02 -0800 2009 | |
| |
uninstall.rb | Wed Aug 13 02:33:32 -0700 2008 |
= 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}[http://www.lucaguidi.com/pages/cached_models].
= 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
end
class Developer < ActiveRecord::Base
belongs_to :project, :cached => true
end
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
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
= Install
There are three ways to install CachedModels
Gemified plugin:
environment.rb
Rails::Initializer.run do |config|
config.gem 'cached-models'
end
$ (sudo) rake gems:install
$ rake gems:unpack
Rails plugin:
$ ./script/plugin install git://github.com/jodosha/cached-models.git
Standalone:
$ (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://github.com/jodosha/cached-models.git
$ rake cached_models
* Create a ticket to the {Sushistar Lighthouse page}[http://sushistar.lighthouseapp.com]
* Create a patch and add as attachment to the ticket.
Copyright (c) 2008 Luca Guidi, released under the MIT license











