Skip to content

Instantly share code, notes, and snippets.

@Gregg
Created February 5, 2009 03:20
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 Gregg/58531 to your computer and use it in GitHub Desktop.
Save Gregg/58531 to your computer and use it in GitHub Desktop.
# To add a folder for sweepers
# /config/environment.rb
config.load_paths += %W( #{RAILS_ROOT}/app/sweepers )
# The Typical Sweeper
# /app/sweepers/post_sweeper.rb
class PostSweeper < ActionController::Caching::Sweeper
observe Post
def after_save(post)
clear_posts_cache(post)
end
def after_destroy(post)
clear_posts_cache(post)
end
def clear_posts_cache(post)
expire_page :controller => :posts,
:action => :index
expire_page :controller => :posts,
:action => :show,
:id => post
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment