mattallen / cached-partials

Set and forget Caching for Rails

This URL has Read+Write access

mattallen (author)
Tue Apr 07 20:30:34 -0700 2009
commit  5251020ca9413c248ff0ee68acd49f71aa8252aa
tree    db821d63006843523ccb54038654b38a52f5f5d6
parent  7ec315fe29d3e6c2a074c9abf89aae43422c2ce4
name age message
file README Loading commit data...
directory controllers/
directory helpers/
file init.rb
directory lib/
README
Cached Partials
=========

Cached partials allows you to control you cache generation from your models. It's a set and forget method once you have 

done the initial setup.  Partials will be re-rendered every time a model is created/saved/destroyed.

Set it up as follows:
  
./script/install plugin git://github.com/tra/spawn.git
./script/install plugin git://github.com/mattallen/cached-partials.git

Set up memcache in environment.rb

config.cache_store = :mem_cache_store, ["localhost", {:namespace => "yourapp-"}]

in environment.rb (or production.rb) include the constants
  
CACHE_URL = "http://localhost:3000"
CACHE_KEY = "some_secrit_key"
FORCE_KEY = "force"

Make a collection and member folder in the views directory of the models you want to cache.

For Members
==========

<% cp_cache("model:method:#{record.id}",{:force => params[FORCE_KEY] == "1"}) do %>
  ## record variable contains your record
<% end %>

For Collections
==========
<% cp_cache("model:method",{:force => params[FORCE_KEY] == "1"}) do %>
  <% @posts = Post.last_5 %>
  ## as above, call a named scope or class method to retrieve needed records
<% end %>