# Unable to clear cached pages

**URL:** <https://www.ruby-forum.com/t/unable-to-clear-cached-pages/147727>\
**Category:** Rails\
**Created:** [September 4, 2008, 6:46pm UTC](https://www.ruby-forum.com/t/unable-to-clear-cached-pages/147727 "2008-09-04T18:46:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindtriggerz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mindtriggerz](https://www.ruby-forum.com/u/mindtriggerz)\
**Post date:** [September 4, 2008, 6:46pm UTC](https://www.ruby-forum.com/t/unable-to-clear-cached-pages/147727/1 "2008-09-04T18:46:47Z")

</div>

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:

```auto
caches_page :index, :no_site
```

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

```auto
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

---

<div class="post-metadata">

**Author:** ![mindtriggerz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mindtriggerz](https://www.ruby-forum.com/u/mindtriggerz)\
**Post date:** [September 4, 2008, 7:18pm UTC](https://www.ruby-forum.com/t/unable-to-clear-cached-pages/147727/2 "2008-09-04T19:18:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mindtriggerz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mindtriggerz](https://www.ruby-forum.com/u/mindtriggerz)\
**Post date:** [September 4, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/unable-to-clear-cached-pages/147727/3 "2008-09-04T19:45:55Z")

</div>

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
