Sha256: d0e1d0559ba02b42f58b50de3dc39544e6f88a9802c466d3de195064d49fd623

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

class CommentSweeper < ActionController::Caching::Sweeper
  observe Comment

  def after_create(comment)
    expire_cache_for(comment)
  end
  
  # If our sweeper detects that a comment was updated call this
  def after_update(comment)
    expire_cache_for(comment)
  end
  
  # If our sweeper detects that a comment was deleted call this
  def after_destroy(comment)
    expire_cache_for(comment)
  end
          
  private
  def expire_cache_for(record)
    # Expire the footer content
    expire_action :controller => 'base', :action => 'footer_content'

    if record.commentable_type.eql?('Post') 
      expire_action :controller => 'posts', :action => 'show', :id => record.commentable.to_param , :user_id => record.commentable.user.to_param
      
      if Post.find_recent(:limit => 16).include?(record.commentable)
        # Expire the home page    
        expire_action :controller => 'base', :action => 'site_index'
        # Expire the category pages
        expire_action :controller => 'categories', :action => 'show', :id => record.commentable.category
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
community_engine-2.3.0 app/controllers/comment_sweeper.rb
community_engine-2.1.0 app/controllers/comment_sweeper.rb
community_engine-2.0.0 app/controllers/comment_sweeper.rb
community_engine-2.0.0.beta3 app/controllers/comment_sweeper.rb
community_engine-2.0.0.beta2 app/controllers/comment_sweeper.rb
community_engine-2.0.0.beta1 app/controllers/comment_sweeper.rb