Skip to content

Instantly share code, notes, and snippets.

@scott
Created February 10, 2009 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scott/61700 to your computer and use it in GitHub Desktop.
Save scott/61700 to your computer and use it in GitHub Desktop.
class DocSweeper < ActionController::Caching::Sweeper
observe Doc
def after_save(doc)
expire_page_for(doc)
end
def after_destroy(doc)
expire_page_for(doc)
end
private
def expire_page_for(record)
expire_page(page_path(record.category.link, record.permalink))
#Expire home page
expire_page(root_path)
#Expire related pages too
expire_page :controller => 'categories', :action => 'show', :id => record.category.link
Doc.in_category(record.category_id).each do |page|
expire_page(page_path(page.category.link, page.permalink))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment