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 (
cached-models / README
| 6a8a9316 » | jodosha | 2008-09-10 | 1 | = CachedModels | |
| 8bed8c12 » | jodosha | 2008-08-13 | 2 | ||
| 665e1568 » | jodosha | 2008-09-10 | 3 | CachedModels provides to your models a transparent approach to use Rails internal caching mechanism. | |
| 8bed8c12 » | jodosha | 2008-08-13 | 4 | ||
| 6a8a9316 » | jodosha | 2008-09-10 | 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 | 10 | ||
| c8d7420f » | jodosha | 2008-09-08 | 11 | Using Memcached and Rails 2.2.1 | |
| 12 | |||||
| 9f6cbcb9 » | jodosha | 2008-09-10 | 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 | 20 | ||
| 8ac4bce2 » | jodosha | 2008-09-02 | 21 | class Project < ActiveRecord::Base | |
| 22 | has_many :developers, :cached => true | ||||
| c8d7420f » | jodosha | 2008-09-08 | 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 | 27 | end | |
| 28 | |||||
| 29 | class Developer < ActiveRecord::Base | ||||
| c8d7420f » | jodosha | 2008-09-08 | 30 | belongs_to :project, :cached => true | |
| 8ac4bce2 » | jodosha | 2008-09-02 | 31 | end | |
| 32 | |||||
| c8d7420f » | jodosha | 2008-09-08 | 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 | 49 | ||
| 6a8a9316 » | jodosha | 2008-09-10 | 50 | = Install | |
| 51 | |||||
| b98a7973 » | jodosha | 2008-10-10 | 52 | There are three ways to install CachedModels | |
| 6a8a9316 » | jodosha | 2008-09-10 | 53 | ||
| b98a7973 » | jodosha | 2008-10-10 | 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 | 81 | ||
| 82 | |||||
| 83 | = Contribute | ||||
| 84 | |||||
| 85 | * Check out the code and test it: | ||||
| b98a7973 » | jodosha | 2008-10-10 | 86 | $ git clone git://github.com/jodosha/cached-models.git | |
| 6a8a9316 » | jodosha | 2008-09-10 | 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 | 94 | ||
| 95 | Copyright (c) 2008 Luca Guidi, released under the MIT license | ||||







