# Expire\_fragment Strange behavior

**URL:** <https://www.ruby-forum.com/t/expire-fragment-strange-behavior/153969>\
**Category:** Deployment\
**Created:** [November 24, 2008, 6:05am UTC](https://www.ruby-forum.com/t/expire-fragment-strange-behavior/153969 "2008-11-24T06:05:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 24, 2008, 6:05am UTC](https://www.ruby-forum.com/t/expire-fragment-strange-behavior/153969/1 "2008-11-24T06:05:34Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [November 24, 2008, 6:10am UTC](https://www.ruby-forum.com/t/expire-fragment-strange-behavior/153969/2 "2008-11-24T06:10:24Z")

</div>

Sorry, wrong forum…re-posted under ‘rails’
