Forum: Ruby on Rails conditional expire_fragment

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.
Richard S. (Guest)
on 2008-11-26 19:51
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 topic is locked and can not be replied to.