I’m following railscasts tutorial on fragment caching, everything works
great except for the sweepers. When i put expire_fragment(%r{.*})
directly in my controller, i can expire my fragments with wonderful
ease. Yet when i write a nice little sweeper like this code block,
nothing gets expired (the puts have been added in for troubleshooting):
class PhraseSweeper < ActionController::Caching::Sweeper
observe Phrase
def after_update(phrase)
expire_cache(phrase)
end
def expire_cache(phrase)
puts "=====This Is Activated Via expire_cache(phrase) "
puts expire_fragment(%r{.}).class
expire_fragment(%r{.})
end
end
I put this put it in apps/sweepers, and initialize the folder under
environment.rb. When i update my phrase model I get this in my console:
=====This Is Activated Via expire_cache(phrase)
NilClass
=====This Is Activated Via expire_cache(phrase)
NilClass
Yet when i have the expire_fragment called via my controller i get this
in the console:
======This is called via the controller======
Hash
So, my sweeper folder is getting initialized, and the code is running on
update, but for some reason the puts are called twice, and the
expire_fragment doesn’t work at all. Rails 2.1.0 Ruby 1.8.6. Any
suggestions??