Cache sweeper not getting called

Hi,

I’ve started to implement page caches but I’ve hit a brick wall getting
a sweeper to clear the cache when needed. It seems that any models that
I tell it to observe aren’t being observed properly. If I add the
sweeper to a controller the initialize method runs, but no matter what I
do the after_save/after_update callbacks aren’t running. Also if I try
to call “expire_page”, I get a method missing error. It seems like the
class isn’t actually extending the Sweeper at all, is there something
I’m missing??

Here’s the sweeper code:

class PublishSweeper < ActionController::Caching::Sweeper

observe Program

def initialize
puts “sweeper initialised”
end

def after_save(record)
puts “The sweeper knows that node: #{record.inspect} has been
saved!”
end

def after_update(record)
puts “The sweeper knows that node: #{record.inspect} has been
updated!”
end

end

Daniel G. wrote:

Hi,

I’ve started to implement page caches but I’ve hit a brick wall getting
a sweeper to clear the cache when needed. It seems that any models that
I tell it to observe aren’t being observed properly. If I add the
sweeper to a controller the initialize method runs, but no matter what I
do the after_save/after_update callbacks aren’t running. Also if I try
to call “expire_page”, I get a method missing error. It seems like the
class isn’t actually extending the Sweeper at all, is there something
I’m missing??

Did you tell your controller to use the sweeper?

class PublishController < ApplicationController
cache_sweeper :publish_sweeper
end

Yep, I’ve got the sweeper being used in a couple of controllers - all
of them initialize it, but no model changes are being observed (or at
least the sweeper isn’t being alerted to the model changes)

Did you tell config/environment.rb where and how to load the sweepers?
That
one bite me a while back. If you didn’t add it to config.load_paths in
the
Rails::Initializer block there. Hope that helps.

RSL

Russell N. wrote:

Did you tell config/environment.rb where and how to load the sweepers?
That
one bite me a while back. If you didn’t add it to config.load_paths in
the
Rails::Initializer block there. Hope that helps.

RSL

Thanks for the responses, I think I’m going to blame webrick - even when
I configrated (my new favourite made up word) caching in dev mode,
webrick didn’t play nice. Switching to mongrel seems to make it happy.

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