Sha256: 078369dc1b266fd4a1036a05fa692bf2be4c94ab2a68bcb1ff027beb296b4053

Contents?: true

Size: 1007 Bytes

Versions: 6

Compression:

Stored size: 1007 Bytes

Contents

class PageSweeper < ActionController::Caching::Sweeper
  observe Page # This sweeper is going to keep an eye on the Page model

  # If our sweeper detects that a Page was created call this
  def after_create(page)
    expire_cache_for(page)
  end
  
  # If our sweeper detects that a Page was updated call this
  def after_update(page)
    expire_cache_for(page)
  end
  
  # If our sweeper detects that a Page was deleted call this
  def after_destroy(page)
    expire_cache_for(page)
  end
          
  private
  def expire_cache_for(record)
    # Expire the home page
    expire_action(:controller => 'base', :action => 'site_index')

    # Expire the footer content
    expire_action(:controller => 'base', :action => 'footer_content')
    
    # Also expire the sitemap
    expire_action(:controller => 'sitemap', :action => 'index')

    # Also expire the show pages, in case we just edited/deleted a page
    expire_action(:controller => 'pages', :action => 'show', :id => record.to_param)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
community_engine-2.3.0 app/controllers/page_sweeper.rb
community_engine-2.1.0 app/controllers/page_sweeper.rb
community_engine-2.0.0 app/controllers/page_sweeper.rb
community_engine-2.0.0.beta3 app/controllers/page_sweeper.rb
community_engine-2.0.0.beta2 app/controllers/page_sweeper.rb
community_engine-2.0.0.beta1 app/controllers/page_sweeper.rb