Sha256: 964c271f42580e94aa2f035982136013fc0166c6c0b74837e50f07293c1357d4

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

class SpudPostCategorySweeper < ActionController::Caching::Sweeper

  observe SpudPostCategory

  def after_save(record)
    expire_cache_for(record)
  end

  def after_destroy(record)
    expire_cache_for(record)
  end

  private

  def expire_cache_for(record)
    if Spud::Blog.config.cache_mode = :action
      SpudPost.find_each do |p|
        if p.is_news && Spud::Blog.config.news_enabled
          expire_action news_post_url(p.url_name)
        elsif Spud::Blog.config.blog_enabled
          expire_action blog_post_url(p.url_name)
        end
      end
      expire_action news_url if Spud::Blog.config.news_enabled
      expire_action blog_url if Spud::Blog.config.blog_enabled
      expire_action spud_blog_sitemap_url
    end
    if Spud::Blog.config.cache_mode = :full_page
      SpudPost.find_each do |p|
        if p.is_news && Spud::Blog.config.news_enabled
          expire_page news_post_path(p.url_name)
        elsif Spud::Blog.config.blog_enabled
          expire_page blog_post_path(p.url_name)
        end
      end
      expire_page news_path if Spud::Blog.config.news_enabled
      expire_page blog_path if Spud::Blog.config.blog_enabled
      expire_page spud_blog_sitemap_path(:format => :xml)
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
tb_blog-1.0.4 app/models/spud_post_category_sweeper.rb
tb_blog-1.0.3 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.11 app/models/spud_post_category_sweeper.rb
tb_blog-1.0.2 app/models/spud_post_category_sweeper.rb
tb_blog-1.0.1 app/models/spud_post_category_sweeper.rb
tb_blog-1.0 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.10 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.9 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.8 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.7 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.5 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.4 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.3 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.2 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.1 app/models/spud_post_category_sweeper.rb
spud_blog-0.9.0 app/models/spud_post_category_sweeper.rb