Project

memorize

0.0
No commit activity in last 3 years
No release in over 3 years
Allows Rails applications to do and control cache of actions
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

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