Unable to clear cached pages

I am trying to utilize page caching in my application, and have done the
following:

config.action_controller.perform_caching = true config.action_view.cache_template_extensions = false
(What is that second setting above??)

In a controller with actions being cached:

caches_page :index, :no_site

In a controller where the cached pages need to get cleared:

cache_sweeper :site_sweeper, :only => [:update]

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:

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")
…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

I’m not quite sure where to head with this (I use fragment caching) but:

-> Which version of Rails are you using?
-> Do you see anything in the web server logs? Maybe the Rails login
doesn’t have the rights to dicker with files in the web server’s cache
folder?
-> Perhaps your paths aren’t equivalent? By that I mean that the path to
the cached page isn’t the same as the path you’re attempting to expire
with…
-> Can you test this in development where you have (I hope) full control
over the application stack?

Please see my responses below:

Ar Chron wrote:

I’m not quite sure where to head with this (I use fragment caching) but:

-> Which version of Rails are you using?

Using Rails 2.0.2. Locally, i’m developing on Windows XP with
InstantRails 2.0, which consists of:

* Upgrades Ruby to version 1.8.6 Patch Level 111
* Upgrades Rails to 2.0.2
* Upgrades Mongrel to 1.1.2
* Upgrades RubyGems? to 1.0.1
* Upgrades Rake to 0.8.1

The live development server is Linux, same version of Rails. It’s
running in production mode, i’m running in development locally. But i’m
turning caching on in each respectively, when trying to get it working.

-> Do you see anything in the web server logs? Maybe the Rails login
doesn’t have the rights to dicker with files in the web server’s cache
folder?

Where would i look to see anything in the ‘web server logs’ when Mongrel
is serving the site? Somewhere beyond /log/development.log? Also, i’m using the default cache location
()/public).

-> Perhaps your paths aren’t equivalent? By that I mean that the path to
the cached page isn’t the same as the path you’re attempting to expire
with…

This is my most likely hypothesis right now, but i’m having a hard time
testing it. From what i can tell, the ‘expire_page’ function utilizes
the ‘page_cache_path’ function to figure out the path to the cached
page, and when i call that function myself it returns nil. The source
for the ‘expire_page’ function looks like this:

65: def expire_page(path)
66: return unless perform_caching
67:
68: benchmark “Expired page: #{page_cache_file(path)}” do
69: File.delete(page_cache_path(path)) if
File.exist?(page_cache_path(path))
70: end
71: end

perform_caching is true, i’ve tested that, but i’ve never seen the
“Expired page: xxx” entry in the development.log. Under what
circumstances does ‘benchmark’ get executed?

-> Can you test this in development where you have (I hope) full control
over the application stack?

As i mentioned, i am testing this locally - if you have any specific
tests to perform or other ideas i’d be very appreciative.

j

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs