Sha256: 3096024167f2d86cdecc41525f28112cb3f34fa880691930a7a9704bae2641b8

Contents?: true

Size: 1.21 KB

Versions: 23

Compression:

Stored size: 1.21 KB

Contents

class ContentSweeper < ActionController::Caching::Sweeper
  # observe Article, Comment, Settings

  def after_save(record)
    case record
    when ::Article, ::Settings
      remove_articles_cache
    when ::Comment
      case record.commentable
      when ::Article
        expire_article(record.commentable)
      end
    end

    remove_archive_cache
  end

  def after_destroy(record)
    after_save(record)
  end

  def expire_article(article)
    expire_page(article_permalink_path(article.published_at.year,article.published_at.month,article.published_at.day,article.permalink)) unless article.published_at.nil?
  end

  # removes all the articles pages
  def remove_articles_cache
    Article.find(:all).each do |article|
      expire_article(article)
    end
  end
  
  # removes the entirety of the articles folder which all the articles archive and
  # pagination stuff is cached in    
  def remove_archive_cache
    expire_action(:controller => '/articles', :action => 'index')
    expire_fragment(%r{/articles/page/*})
    expire_fragment(%r{/categories/*})
    articles_folder = ActionController::Base.page_cache_directory + '/articles/'
    FileUtils.rmtree articles_folder if File.exists? articles_folder      
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
beef-admin_area-0.1.0 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.1 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.2 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.3 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.4 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.6 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.1.7 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.9 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.8 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.7 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.6 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.4 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.3 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.2 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.3.0 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.2.6 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.2.5 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.2.4 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.2.3 generators/admin_area_files/templates/app/models/content_sweeper.rb
beef-admin_area-0.2.2 generators/admin_area_files/templates/app/models/content_sweeper.rb