You are here: Browse Railsplugins Action Cache Layout
Copyright© 2008 José Valim (jose.valim at gmail dot com) Site: http://www.pagestacker.com/ License: MIT Version: 1.0
This plugin was inspired in content_cache and both have the same idea, but they solve the problem differently. You can check content_cache at:
http://svn.codahale.com/content_cache/
= Description
In almost all Rails applications, the layout contains dynamic information like the username or the number of itens in a cart. But since caches_action method always caches the layout with the action content, You cannot use it to cache Your products pages in an e-commerce store, cause it means caching the cart within that page.
Action cache layout enables the caching of actions without layout in Rails. By setting :without_layout => true, none of the layout is cached, allowing You to provide some dynamic, user-specific content while reducing DB loads and rendering times.
If You got Yourself using fragment cache in a whole action, this plugin is for You! =)
= Install
Just run in your application root:
ruby script/plugin install http://action-cache-layout.googlecode.com/svn/trunk/
= Example
class NotesController < ActionController::Base
caches_action :index, :without_layout => true
end
def index
@notes = Note.find(:all, :include => [:monkeys, dirigibles, robots])
end
The first time /notes/index is requested, #index is executed and whatever it renders is stored wherever you have the cache store configured. None of the layout is stored, just the rendered view. The next time /notes/index is requested, the action content is read from the cache, placed within the layout, and sent to the client.
The plugin also allows to show flash messages with cached pages as long as it is showed in Your layouts.
= Remember!
Remember that the action method is not performed. So if You do at some point
render :action => 'index', :layout => 'different_layout'
The plugin will try to render the default layout and not the’different_layout’ sent in the hash above. And remember that only before_filters are performed, no after_filters.
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly