From 98b2efdb5b02081783035dc6f9721d44ccface73 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 2 Apr 2006 06:17:05 +0000 Subject: [PATCH] Blow away page caches when web settings are changed --- app/controllers/admin_controller.rb | 1 + app/controllers/cache_sweeping_helper.rb | 21 ++++++++++++++++++++ app/controllers/revision_sweeper.rb | 25 ++++++++---------------- app/controllers/web_sweeper.rb | 14 +++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 app/controllers/cache_sweeping_helper.rb create mode 100644 app/controllers/web_sweeper.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index a52b2005..4390359d 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -3,6 +3,7 @@ require 'application' class AdminController < ApplicationController layout 'default' + cache_sweeper :web_sweeper def create_system if @wiki.setup? diff --git a/app/controllers/cache_sweeping_helper.rb b/app/controllers/cache_sweeping_helper.rb new file mode 100644 index 00000000..fe4098ff --- /dev/null +++ b/app/controllers/cache_sweeping_helper.rb @@ -0,0 +1,21 @@ +module CacheSweepingHelper + + def expire_cached_page(web, page_name) + expire_action :controller => 'wiki', :web => web.address, + :action => %w(show published), :id => page_name + end + + def expire_cached_summary_pages(web) + categories = WikiReference.find(:all, :conditions => "link_type = 'C'") + %w(recently_revised list).each do |action| + expire_action :controller => 'wiki', :web => web.address, :action => action + categories.each do |category| + expire_action :controller => 'wiki', :web => web.address, :action => action, :category => category.referenced_name + end + end + + expire_action :controller => 'wiki', :web => web.address, :action => 'authors' + expire_fragment :controller => 'wiki', :web => web.address, :action => %w(rss_with_headlines rss_with_content) + end + +end \ No newline at end of file diff --git a/app/controllers/revision_sweeper.rb b/app/controllers/revision_sweeper.rb index d77d644b..1db2d2c6 100644 --- a/app/controllers/revision_sweeper.rb +++ b/app/controllers/revision_sweeper.rb @@ -1,4 +1,9 @@ +require_dependency 'cache_sweeping_helper' + class RevisionSweeper < ActionController::Caching::Sweeper + + include CacheSweepingHelper + observe Revision, Page def after_save(record) @@ -16,23 +21,9 @@ class RevisionSweeper < ActionController::Caching::Sweeper private def expire_caches(page) - web = page.web - - ([page.name] + WikiReference.pages_that_reference(page.name)).uniq.each do |page_name| - expire_action :controller => 'wiki', :web => web.address, - :action => %w(show published), :id => page_name - end - - categories = WikiReference.find(:all, :conditions => "link_type = 'C'") - %w(recently_revised list).each do |action| - expire_action :controller => 'wiki', :web => web.address, :action => action - categories.each do |category| - expire_action :controller => 'wiki', :web => web.address, :action => action, :category => category.referenced_name - end - end - - expire_action :controller => 'wiki', :web => web.address, :action => 'authors' - expire_fragment :controller => 'wiki', :web => web.address, :action => %w(rss_with_headlines rss_with_content) + expire_cached_summary_pages(page.web) + pages_to_expire = ([page.name] + WikiReference.pages_that_reference(page.name)).uniq + pages_to_expire.each { |page_name| expire_cached_page(page.web, page_name) } end end diff --git a/app/controllers/web_sweeper.rb b/app/controllers/web_sweeper.rb new file mode 100644 index 00000000..38e8f3da --- /dev/null +++ b/app/controllers/web_sweeper.rb @@ -0,0 +1,14 @@ +require_dependency 'cache_sweeping_helper' + +class WebSweeper < ActionController::Caching::Sweeper + + include CacheSweepingHelper + + observe Web + + def after_save(record) + web = record + web.pages.each { |page| expire_cached_page(web, page.name) } + expire_cached_summary_pages(web) + end +end