public
Description: CachedModels provides to your ActiveRecord objects a transparent approach to use ActiveSupport caching mechanism.
Homepage: http://lucaguidi.com/pages/cached_models
Clone URL: git://github.com/jodosha/cached-models.git
cached-models / README
6a8a9316 » jodosha 2008-09-10 Updated README with project... 1 = CachedModels
8bed8c12 » jodosha 2008-08-13 has_many association support 2
665e1568 » jodosha 2008-09-10 Added project description t... 3 CachedModels provides to your models a transparent approach to use Rails internal caching mechanism.
8bed8c12 » jodosha 2008-08-13 has_many association support 4
6a8a9316 » jodosha 2008-09-10 Updated README with project... 5 Check for news and tutorials at the {project home page}[http://www.lucaguidi.com/pages/cached_models].
6
7
8
9 = Usage
8bed8c12 » jodosha 2008-08-13 has_many association support 10
c8d7420f » jodosha 2008-09-08 Added support for cache exp... 11 Using Memcached and Rails 2.2.1
12
9f6cbcb9 » jodosha 2008-09-10 Updated README with informa... 13 Make sure to configure your current environment with:
14
15 config.cache_classes = true
16 config.action_controller.perform_caching = true
17 config.cache_store = :mem_cache_store
18
19
8bed8c12 » jodosha 2008-08-13 has_many association support 20
8ac4bce2 » jodosha 2008-09-02 Updated README example 21 class Project < ActiveRecord::Base
22 has_many :developers, :cached => true
c8d7420f » jodosha 2008-09-08 Added support for cache exp... 23 has_many :tickets, :cached => true
24 has_many :recent_tickets, :limit => 5,
25 :order => 'id DESC', :cached => true
26
8ac4bce2 » jodosha 2008-09-02 Updated README example 27 end
28
29 class Developer < ActiveRecord::Base
c8d7420f » jodosha 2008-09-08 Added support for cache exp... 30 belongs_to :project, :cached => true
8ac4bce2 » jodosha 2008-09-02 Updated README example 31 end
32
c8d7420f » jodosha 2008-09-08 Added support for cache exp... 33
34 Example 1
35 project.developers # Database fetch and automatic cache storing
36
37 developer = project.developers.last
38 developer.update_attributes :first_name => 'Luca' # Database update and cache expiration for project cache
39
40 Example 2
41 project2.developers # Database fetch and automatic cache storing
42 project2.developers << developer # Database update and cache renewal for both project and project2 caches
43
44 Example 3
45 project.tickets # Database fetch and automatic cache storing
46 ticket = project.recent_tickets.first
47 ticket.update_attributes :state => 'solved' # Database update and cache expiration for both tickets and recent_tickets entries
48
8bed8c12 » jodosha 2008-08-13 has_many association support 49
6a8a9316 » jodosha 2008-09-10 Updated README with project... 50 = Install
51
b98a7973 » jodosha 2008-10-10 Updated README with new ins... 52 There are three ways to install CachedModels
6a8a9316 » jodosha 2008-09-10 Updated README with project... 53
b98a7973 » jodosha 2008-10-10 Updated README with new ins... 54 Gemified plugin:
55
56 environment.rb
57
58 Rails::Initializer.run do |config|
59 config.gem 'cached-models'
60 end
61
62 $ (sudo) rake gems:install
63 $ rake gems:unpack
64
65 Rails plugin:
66
67 $ ./script/plugin install git://github.com/jodosha/cached-models.git
68
69 Standalone:
70
71 $ (sudo) gem install cached-models
72
73 in your project:
74
75 require 'rubygems'
76 require 'activerecord'
77 require 'cached-models'
78
79 ActiveRecord::Base.rails_cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, 'localhost')
80
6a8a9316 » jodosha 2008-09-10 Updated README with project... 81
82
83 = Contribute
84
85 * Check out the code and test it:
b98a7973 » jodosha 2008-10-10 Updated README with new ins... 86 $ git clone git://github.com/jodosha/cached-models.git
6a8a9316 » jodosha 2008-09-10 Updated README with project... 87 $ rake cached_models
88
89 * Create a ticket to the {Sushistar Lighthouse page}[http://sushistar.lighthouseapp.com]
90
91 * Create a patch and add as attachment to the ticket.
92
93
8bed8c12 » jodosha 2008-08-13 has_many association support 94
95 Copyright (c) 2008 Luca Guidi, released under the MIT license