Sha256: d84d0e86609aec5b8028e65eb019f1bd07d007b9ae1f69d42612e2c6f036f992

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

class CmsContentSweeper < ActionController::Caching::Sweeper
  observe CmsPage, CmsTemplate, CmsSnippet
  
  def after_save(record)
    delete_all_cached_pages
  end
  
  def after_destroy(record)
    delete_all_cached_pages
  end
  
  def delete_all_cached_pages
    if File.expand_path(Management::CmsController.page_cache_directory) == File.expand_path("#{Rails.root}/public")
      # expire home page
      expire_page :controller => 'cms/content', :action => 'show', :content_path => nil
      
      # expire all other pages
      CmsPage.select([ :id, :path ]).find_each do |page|
        expire_page :controller => 'cms/content', :action => 'show', :content_path => page.path.split('/')
      end
    else
      FileUtils.rm_r(Dir.glob("#{cache_dir}/*")) rescue Errno::ENOENT
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
imagine_cms-4.1.0 app/sweepers/cms_content_sweeper.rb
imagine_cms-4.0.1 app/sweepers/cms_content_sweeper.rb
imagine_cms-4.0.0 app/sweepers/cms_content_sweeper.rb