Forum: Ruby on Rails trouble expiring cached pages

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charlie B. (Guest)
on 2006-04-09 03:33
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 (0.00024)
Charlie B. (Guest)
on 2006-04-09 20:02
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
Charlie B. (Guest)
on 2006-04-10 05:10
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
This topic is locked and can not be replied to.