Sha256: 02b0541117c583d53a01c136c19a8fd04061dd9419fd1838db17a342a913ef85

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

module Alchemy
  class ContentSweeper < ActionController::Caching::Sweeper

    observe Element, Page

    def after_create(object)
      expire_contents_displayed_as_select
    end

    def after_update(object)
      if object.class.to_s == "Alchemy::Element"
        expire_cache_for(object.contents)
        expire_contents_displayed_as_select
      elsif object.class.to_s == "Alchemy::Page" && (object.urlname_changed? || object.name_changed?)
        expire_contents_displayed_as_select
      end
    end

    def after_destroy(object)
      if object.class.to_s == "Alchemy::Element"
        expire_cache_for(object.contents)
      elsif object.class.to_s == "Alchemy::Page"
        expire_contents_displayed_as_select
      end
    end

  private

    def expire_cache_for(contents)
      contents.each do |content|
        expire_fragment(content)
      end
    end

    # Expires all EssenceSelect content editor cache fragments.
    def expire_contents_displayed_as_select
      Content.essence_selects.each { |content| expire_fragment(content) }
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alchemy_cms-2.2.4 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.3.2 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.3.1 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.3.rc5 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.2 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.1 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.0 app/sweepers/alchemy/content_sweeper.rb
alchemy_cms-2.2.rc15 app/sweepers/alchemy/content_sweeper.rb