2007-01-22 14:43:50 +01:00
|
|
|
require_dependency 'cache_sweeping_helper'
|
|
|
|
|
|
|
|
class RevisionSweeper < ActionController::Caching::Sweeper
|
|
|
|
|
|
|
|
include CacheSweepingHelper
|
|
|
|
|
|
|
|
observe Revision, Page
|
|
|
|
|
2009-08-04 07:02:04 +02:00
|
|
|
def before_save(record)
|
2009-12-14 04:09:12 +01:00
|
|
|
if record.is_a?(Revision)
|
|
|
|
expire_cached_page(record.page.web, record.page.name)
|
2009-08-04 07:02:04 +02:00
|
|
|
expire_cached_revisions(record.page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def after_save(record)
|
|
|
|
if record.is_a?(Revision)
|
|
|
|
expire_caches(record.page)
|
|
|
|
end
|
|
|
|
end
|
2011-09-21 06:46:36 +02:00
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
if record.is_a?(Page)
|
|
|
|
WikiReference.pages_that_reference(record.web, record.name).each do |page_name|
|
|
|
|
expire_cached_page(record.web, page_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
def after_delete(record)
|
|
|
|
if record.is_a?(Page)
|
|
|
|
expire_caches(record)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-09 18:33:41 +02:00
|
|
|
def self.expire_page(web, page_name)
|
|
|
|
new.expire_cached_page(web, page_name)
|
2011-09-09 07:05:54 +02:00
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def expire_caches(page)
|
|
|
|
expire_cached_summary_pages(page.web)
|
2011-09-21 06:46:36 +02:00
|
|
|
pages_to_expire = ([page.name] +
|
2009-06-03 06:36:39 +02:00
|
|
|
WikiReference.pages_redirected_to(page.web, page.name) +
|
|
|
|
WikiReference.pages_that_include(page.web, page.name)).uniq
|
2007-01-22 14:43:50 +01:00
|
|
|
pages_to_expire.each { |page_name| expire_cached_page(page.web, page_name) }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|