diff --git a/app/controllers/revision_sweeper.rb b/app/controllers/revision_sweeper.rb new file mode 100644 index 00000000..21421c7b --- /dev/null +++ b/app/controllers/revision_sweeper.rb @@ -0,0 +1,24 @@ +class RevisionSweeper < ActionController::Caching::Sweeper + observe Revision, Page + + def after_save(record) + if record.is_a?(Revision) + expire_caches(record.page) + end + end + + def after_delete(record) + if record.is_a?(Page) + expire_caches(record) + end + end + + private + + def expire_caches(page) + expire_page :controller => 'wiki', :web => page.web.address, + :action => %w(show published), :id => page.name + expire_page :controller => 'wiki', :web => page.web.address, + :action => %w(authors recently_revised list rss_with_content rss_with_headlines) + end +end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 62905dcf..bd66c960 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -6,8 +6,9 @@ require 'zip/zip' class WikiController < ApplicationController # TODO implement cache sweeping - caches_page :show, :published - + caches_page :show, :published, :authors, :recently_revised, :list, :rss_with_content, :rss_with_headlines + cache_sweeper :revision_sweeper + layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html] def index @@ -194,6 +195,7 @@ class WikiController < ApplicationController redirect_to_page @page_name rescue => e flash[:error] = e + logger.error e flash[:content] = @params['content'] if @page @page.unlock