Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created August 26, 2011 07:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marshluca/1172861 to your computer and use it in GitHub Desktop.
Save marshluca/1172861 to your computer and use it in GitHub Desktop.
Rails Action Cache
class ListsController < ApplicationController
before_filter :authenticate, :except => :public
caches_page :public
caches_action :index, :if => proc do
!request.format.json? # cache if is not a JSON request
end
caches_action :show, :cache_path => { :project => 1 },
:expires_in => 1.hour
caches_action :feed, :cache_path => proc do
if params[:user_id]
user_list_url(params[:user_id, params[:id])
else
list_url(params[:id])
end
end
end
# http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html
class ListsController < ApplicationController
before_filter :authenticate, :except => :public
caches_page :public
caches_action :index, :if => proc do
!request.format.json? # cache if is not a JSON request
end
caches_action :show, :cache_path => { :project => 1 },
:expires_in => 1.hour, :layout => false
caches_action :feed, :cache_path => proc do
if params[:user_id]
user_list_url(params[:user_id, params[:id])
else
list_url(params[:id])
end
end
end
# http://api.rubyonrails.org/classes/ActionController/Caching/Actions.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment