Skip to content

Instantly share code, notes, and snippets.

@gaahrdner
Created August 31, 2011 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaahrdner/1183719 to your computer and use it in GitHub Desktop.
Save gaahrdner/1183719 to your computer and use it in GitHub Desktop.
## RELEVANT LOG FILE
Expire page /Users/pheezy/code/x/public/applications/app-name.html (0.0ms)
Expire page /Users/pheezy/code/x/public/applications.html (0.0ms)
Expire fragment views/localhost:3000/applications/app-name (0.1ms)
Expire fragment views/localhost:3000/applications (0.1ms)
# CONTROLLER
# caching
caches_page :index, :if => Proc.new {|c| c.request.format.json? }
caches_page :show, :if => Proc.new {|c| c.request.format.json? }
# caches_action :show , :if => Proc.new { |c| !c.request.format.json? }, :cache_path => Proc.new { |c| c.params }
# caches_action :index, :if => Proc.new { |c| !c.request.format.json? }, :cache_path => Proc.new { |c| c.params }
cache_sweeper :application_sweeper #, :only => [ :index, :show ]
## SWEEPER
class ApplicationSweeper < ActionController::Caching::Sweeper
# Listen to events from Application
observe Application
# If an app is created
def after_create(application)
expire_cache_for(application)
end
# If an app is updated
def after_update(application)
expire_cache_for(application)
end
# If an app is destroyed
def after_destroy(application)
expire_cache_for(application)
end
private
def expire_cache_for(application)
expire_page( :controller => "applications", :action => "show" )
expire_page( :controller => "applications", :action => "index" )
expire_action( :controller => "applications", :action => "show" )
expire_action( :controller => "applications", :action => "index" )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment