Created
January 27, 2010 00:49
-
-
Save kdwinter/287428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% cache 'recent_pages' do %> | |
<% @pages.each do |page| %> | |
<%=h page.title %> | |
<%# ... %> | |
<% end %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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