Allows Rails applications to do and control cache of actions
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
MIT-LICENSE
README.textile
Rakefile
memorize.gemspec

README.textile

Memorize:

Allows Rails applications to do and control cache of actions.
With Memorize, you can expires your actions, calling a method in your model (or a CustomClass).
if you’ve suffered with Rails caches_action and is tired of trying to expire your cache, Memorize is for you !
See below my ‘code-explanation’:



  class Article < ActiveRecord::Base
    extend Memorize::Keys
    [...]
  end
  
  class TestController < ApplicationController
  
    #'classic' case of index, with categories, pagination and format support.
    memorize_action :index, :key_builder => Article, :params => [:category, :page, :format]
  
    #case of id, slug ... etc. Accessing a resource with identification.
    memorize_action :show,  :key_builder => Article, :key_param => :slug, :params => [:page, :format]
  
    #case of 'custom' key, if you want to use a 'home made' solution. (here Memorize don't know how expires)
    memorize_action :custom, :cache_path => lambda { |controller| "my_key" }
  
    [...]
  end
  
  class ArticleSweeper < ActionController::Caching::Sweeper
    observe Article
    def after_save(article)
      Article.cache_expires(:index)
      Article.cache_expires(:show, :key => article.slug)
  
      Rails.cache.delete("my_key")  #Memorize does not handle custom keys
    end
  end

More

Memorize is designed to be simple and objetive.
Used and tested for Rails 2.3.x

Install

Just execute:

  sudo gem install memorize

And add to your environment.

Important: you can configure Memorize cache_store, adding a memorize.rb to your config/initializers. Example:


  #Some examples to set Memorize cache_store:
  Memorize.cache_store = Rails.cache
  #Memorize.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
  #Memorize.cache_store = ActiveSupport::Cache.lookup_store(:mem_cache_store, '127.0.0.1:11211')
  
  #Your models can be 'Keys factories'
  #ActiveRecord::Base.extend Memorize::Keys

Bugs and Feedback

If you find any issues, use Github issues tracker.

Copyright © 2010 Roger Leite
1up4dev