# Expire\_page not working

**URL:** <https://www.ruby-forum.com/t/expire-page-not-working/114269>\
**Category:** Rails\
**Created:** [September 10, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/expire-page-not-working/114269 "2007-09-10T19:06:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KenM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@KenM](https://www.ruby-forum.com/u/KenM)\
**Post date:** [September 10, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/expire-page-not-working/114269/1 "2007-09-10T19:06:11Z")

</div>

I’ve enabled page caching on a site I’m currently constructing. The  
sweeper is called upon any changes made to the model, as expected.  
The sweeper code is as follows:

class PersonSweeper \< ActionController::Caching::Sweeper

observe Person

def after\_update(person)  
expire\_staff\_page  
end

def after\_destroy(person)  
expire\_staff\_page  
end

def expire\_staff\_page  
$stderr.puts “@@@@@ Expiring staff page”  
expire\_page( :controller =\> ‘welcome’, :action =\> ‘staff’ )  
$stderr.puts “@@@@@ Staff Page Expired”  
end  
end

In my administrative controller, I have

class Admin::PeopleController \< Admin::AdminBaseController

cache\_sweeper :person\_sweeper

and finally, in the public controller, I have

class WelcomeController \< ApplicationController

caches\_page :staff

When I hit the public ‘staff’ page, the cache file is created. When  
changes are made to the underlying data model, the sweeper method is  
invoked, and I see

@@@@@ Expiring staff page  
@@@@@ Staff Page Expired

in the server logs. However, the generated file in public/welcome/  
staff.html is not removed.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![KenM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@KenM](https://www.ruby-forum.com/u/KenM)\
**Post date:** [September 10, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/expire-page-not-working/114269/2 "2007-09-10T20:00:19Z")

</div>

Solved it. Instead of

expire\_page( :controller =\> ‘welcome’, :action =\> ‘staff’ )

I should have used

expire\_page( :controller =\> ‘/welcome’, :action =\> ‘staff’ )

I guess the issue was that I’m trying to expire content generated in a  
controller different from the one that initially created the cached  
page. Instead of expiring ./public/welcome/staff.html, ./public/admin/  
welcome/staff.html was being expired. It didn’t exist, so of course  
nothing happened.

---

<div class="post-metadata">

**Author:** ![KenM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@KenM](https://www.ruby-forum.com/u/KenM)\
**Post date:** [October 17, 2007, 6:27pm UTC](https://www.ruby-forum.com/t/expire-page-not-working/114269/3 "2007-10-17T18:27:12Z")

</div>

I ran into the same administration / sweeper problem. Although I’ve  
got it working, I’m still unclear about how it all works. My  
revelation was that the admin controller needed the  
cache\_sweeper :person\_sweeper , no the ‘front’ controller.
