Sha256: 6e1edffce61f278d65ec244b2670900a89083bfb1e0956d4b048a0deb7eec176

Contents?: true

Size: 865 Bytes

Versions: 10

Compression:

Stored size: 865 Bytes

Contents

class FavoriteSweeper < ActionController::Caching::Sweeper
  observe Favorite

  def after_create(favorite)
    expire_cache_for(favorite)
  end
    
  def after_destroy(favorite)
    expire_cache_for(favorite)
  end
          
  private
  def expire_cache_for(record)
    #the favorite is for a post
    if record.favoritable_type.eql?('Post')
      # expire the show page
      expire_page :controller => 'posts', :action => 'show', :id => record.favoritable, :user_id => record.favoritable.user
      
      if Post.find_recent(:limit => 16).include?(record.favoritable)
        # Expire the home page
        expire_action :controller => 'base', :action => 'site_index'

        # Expire the category page for this post
        expire_action :controller => 'categories', :action => 'show', :id => record.favoritable.category
      end
    end
        
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
community_engine-3.2.0 app/controllers/favorite_sweeper.rb
community_engine-3.0.0 app/controllers/favorite_sweeper.rb
community_engine-2.3.2 app/controllers/favorite_sweeper.rb
community_engine-2.3.1 app/controllers/favorite_sweeper.rb
community_engine-2.3.0 app/controllers/favorite_sweeper.rb
community_engine-2.1.0 app/controllers/favorite_sweeper.rb
community_engine-2.0.0 app/controllers/favorite_sweeper.rb
community_engine-2.0.0.beta3 app/controllers/favorite_sweeper.rb
community_engine-2.0.0.beta2 app/controllers/favorite_sweeper.rb
community_engine-2.0.0.beta1 app/controllers/favorite_sweeper.rb