Sha256: ac0590d3c6db007d68181dd6aade749240e542c1a6b25e93ab003812f20c34ac

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

class BlogSweeper < ActionController::Caching::Sweeper
  observe Article, Category, Feedback, Page, Blog, Sidebar, User

  def after_save(record)
    logger.info "Expiring #{record}, with controller: #{controller}"
    expire_for(record)
  end

  def after_destroy(record)
    expire_for(record, true)
  end

  def expire_for(record, destroying = false)
    case record
    when Page
      sweep_pages(record)
    when Content
      if record.invalidates_cache?(destroying)
        sweep_all
      end
    when Sidebar, Category
      sweep_articles
      sweep_pages(record)
    when Blog, User
      sweep_all
    end
  end

  def sweep_all
    PageCache.sweep_all
    expire_fragment(/.*/)
  end

  def sweep_articles
    PageCache.sweep('/articles/%')
    expire_fragment(%r{.*/articles/.*})
  end

  def sweep_pages(record)
      PageCache.sweep("/pages/#{record.name rescue ''}.html")
      expire_fragment(/.*\/pages\/.*/)
      expire_fragment(/.*\/view_page.*/)
  end

  def logger
    @logger ||= RAILS_DEFAULT_LOGGER || Logger.new(STDERR)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typo-4.1.1 app/models/blog_sweeper.rb
typo-4.1 app/models/blog_sweeper.rb