Conditional expire_fragment

I just recently implemented caching on my site, and i have a sweeper
attached to my :update action, to clear my index (which shows top ranked
items). Is it possible to first check to see if there is a change, and
only expire the cache when appropriate??

my index action looks like this:

def index
unless read_fragment({:page => params[:page] || 1})
@new_phrases = Phrase.find_top(params[:page]||1)
end
end

I want my sweeper action to look something like this:

def expire_cache(phrase)
if read_fragment({:action => ‘index’, :page => 1}) ==
Phrase.find_top(1)
1.upto(5) {|i| expire_fragment(:action => ‘index’, :page => i
) }
end
end

Rails 2.1.0, ruby 1.8.6. Is this type of behavior possible or reasonable
to implement??

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