Skip to content

Instantly share code, notes, and snippets.

@shadowmaru
Created August 23, 2009 22:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shadowmaru/173503 to your computer and use it in GitHub Desktop.
class PageSweeper < ActionController::Caching::Sweeper
observe Page
def after_save(page)
clear_page_cache
end
def after_destroy(page)
clear_page_cache
end
def clear_page_cache
expire_page('/index')
dirs = %w{ pages news }
dirs.each do |dir|
cache_dir = RAILS_ROOT + "/public/#{dir}"
FileUtils.rm_r(Dir.glob(cache_dir+"/*")) rescue Errno::ENOENT
RAILS_DEFAULT_LOGGER.info("Cache directory '#{cache_dir}' fully swept.")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment