Skip to content

Instantly share code, notes, and snippets.

@kdwinter
Created January 27, 2010 00:49
Show Gist options
  • Save kdwinter/287428 to your computer and use it in GitHub Desktop.
Save kdwinter/287428 to your computer and use it in GitHub Desktop.
<% cache 'recent_pages' do %>
<% @pages.each do |page| %>
<%=h page.title %>
<%# ... %>
<% end %>
<% end %>
class PageSweeper < ActionController::Caching::Sweeper
observe Page
[:save, :destroy].each do |action|
class_eval %{
def after_#{action}(page)
expire_cache(page)
end
}
end
protected
def expire_cache(page)
expire_fragment 'recent_pages'
end
#
end
class HomeController < ApplicationController
cache_sweeper :page_sweeper, :only => [:create, :update, :destroy]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment