I am trying to utilize page caching in my application, and have done the following:
[code=]config.action_controller.perform_caching = true config.action_view.cache_template_extensions = false[/code] (What is that second setting above??)
In a controller with actions being cached: [code=]caches_page :index, :no_site[/code] In a controller where the cached pages need to get cleared: [code=]cache_sweeper :site_sweeper, :only => [:update][/code] And finally, the sweeper:
[code=]class SiteSweeper < ActionController::Caching::Sweeper include ActionController::UrlWriter include ActionController::Caching::Pages observe Site # This sweeper is going to keep an eye on the Site model
# If our sweeper detects that a Site was updated call this def after_update(site) if (site.is_production) expire_cache_for(site) end end
private def expire_cache_for(site)
puts "EXPIRING CACHED SITE FOR " + site.geocode
# Expire the two cached actions for the home page (they hold a list of all active sites) #expire_page(:controller => "/wibp_sites", :action => "index") #expire_page(:controller => "/wibp_sites", :action => "no_site") puts page_cache_path("index") expire_page("index") expire_page("wibp_sites/index") expire_page("wibp_sites/no_site")
# Expire all pages for the site, which include controller, action, and id (geocode) expire_page(:controller => "/wibp_home", :action => "index", :id => site.geocode) expire_page(:controller => "/wibp_calendar", :action => "index", :id => site.geocode) expire_page(:controller => "/wibp_officers", :action => "index", :id => site.geocode) expire_page(:controller => "/wibp_other_units", :action => "index", :id => site.geocode) expire_page(:controller => "/wibp_links", :action => "index", :id => site.geocode) end end[/code] As you can hopefully tell, i've tried various tactics to try to get pages swept, including the following versions of the expire_page method: [code=]expire_page(:controller => "wibp_sites", :action => "index") expire_page(:controller => "/wibp_sites", :action => "index") expire_page("/wibp_sites/index") expire_page("wibp_sites/index") expire_page("/wibp_sites/index.html")[/code] ..but nothing has resulted in the cached page files actually being removed (for the page in the example directly above, the cached page is stored at '/public/wibp_sites/index.html'). I have verified that the 'perform_caching' property is true, and the 'puts "EXPIRING CACHED SITE FOR " + site.geocode' line gets executed. Also, when the 'puts page_cache_path("index")' is executed it outputs 'nil'.
Finally, i've never seen the 'Expired page: ' output appear in the log file, and i've seen this in all the tutorials.
Can someone help me diagnose where i'm failing here?
Thanks for your time,
jesse