# Trouble expiring cached pages

**URL:** <https://www.ruby-forum.com/t/trouble-expiring-cached-pages/93766>\
**Category:** Rails\
**Created:** [April 9, 2006, 1:33am UTC](https://www.ruby-forum.com/t/trouble-expiring-cached-pages/93766 "2006-04-09T01:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 9, 2006, 1:33am UTC](https://www.ruby-forum.com/t/trouble-expiring-cached-pages/93766/1 "2006-04-09T01:33:42Z")

</div>

I’m having a bear of a time getting my cached pages to expire. Maybe  
one of you guys can help me out. I’ll show my sweeper and then my log  
to show that it “should” be working.

class PragmaticSweeper \< ActionController::Caching::Sweeper  
observe Comment  
def after\_save(comment)  
expire\_page(comment.post\_id)  
end  
private  
def expire\_page(post\_id)  
logger.error(“I made it to the caching method in the SWEEPER!!!”)  
expire\_action(:controller =\> ‘pragmatic’,  
:action =\> ‘view’,  
:id =\> post\_id)  
end  
end

and now here’s my log that shows that the expiration “should” be  
happening.

SQL (0.000369) INSERT INTO comments (`name`, `raw_comment`, `date`,  
`post_id`, `web_site`, `comment`, `email`) VALUES(‘bbbbbbbbbbbbbbbbb’,  
‘bbbbbbbbbbbbbbbbbbb’, ‘2006-04-08 19:46:25’, 56, ‘’,  
‘bbbbbbbbbbbbbbbbbbb’, ‘’)  
I made it to the caching method in the SWEEPER!!!  
Expired fragment: [banjo.dnsdojo.org:9999/pragmatic/view/56](http://banjo.dnsdojo.org:9999/pragmatic/view/56) (0.00024)

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 9, 2006, 6:02pm UTC](https://www.ruby-forum.com/t/trouble-expiring-cached-pages/93766/2 "2006-04-09T18:02:31Z")

</div>

Anyone got a clue? I’m stumped.

charlie bowman wrote:

> I’m having a bear of a time getting my cached pages to expire. Maybe  
> one of you guys can help me out. I’ll show my sweeper and then my log  
> to show that it “should” be working.
> 
> class PragmaticSweeper \< ActionController::Caching::Sweeper  
> observe Comment  
> def after\_save(comment)  
> expire\_page(comment.post\_id)  
> end  
> private  
> def expire\_page(post\_id)  
> logger.error(“I made it to the caching method in the SWEEPER!!!”)  
> expire\_action(:controller =\> ‘pragmatic’,  
> :action =\> ‘view’,  
> :id =\> post\_id)  
> end  
> end

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [April 10, 2006, 3:10am UTC](https://www.ruby-forum.com/t/trouble-expiring-cached-pages/93766/3 "2006-04-10T03:10:17Z")

</div>

I figured this one out on my own. Here’s the solution if for anyone who  
winds up googling the question. It boils down to not naming your  
expiration method the same name as the one used by the caching module.  
Duh!! I wasted way too much time this!

class PragmaticSweeper \< ActionController::Caching::Sweeper  
observe Comment  
def after\_save(comment)  
expire\_view\_page(comment.post\_id)  
end  
private  
def expire\_view\_page(post\_id)  
logger.error(“I made it to the caching method in the SWEEPER!!!”)  
expire\_page(:controller =\> ‘pragmatic’,  
:action =\> ‘view’,  
:id =\> post\_id)  
end  
end
