RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
cache_sweeper :product_sweeper, :only => [:create, :update, :destroy] caches_action :index, :cache_path => :index_cache_path.to_proc #... private def index_cache_path if admin? '/admin/products' else '/public/products' end end
config.action_controller.perform_caching = true
config.load_paths << "#{RAILS_ROOT}/app/sweepers"
class ProductSweeper < ActionController::Caching::Sweeper observe Product def after_save(product) expire_cache(product) end def after_destroy(product) expire_cache(product) end def expire_cache(product) expire_action '/admin/products' expire_action '/public/products' end end