Cache file_list Action

Also, slightly smarter cache expiry, upon uploading/deleting a file.
This commit is contained in:
Jacques Distler 2009-01-10 22:33:30 -06:00
parent 5c20871ec4
commit b9f5c32755
5 changed files with 17 additions and 5 deletions

View file

@ -16,9 +16,13 @@ module CacheSweepingHelper
end end
end end
%w(authors atom_with_content atom_with_headlines).each do |action| %w(authors atom_with_content atom_with_headlines file_list).each do |action|
expire_action :controller => 'wiki', :web => web.address, :action => action expire_action :controller => 'wiki', :web => web.address, :action => action
end end
%w(file_name created_at).each do |sort_order|
expire_action :controller => 'wiki', :web => web.address, :action => 'file_list', :sort_order => sort_order
end
end end
end end

View file

@ -4,13 +4,18 @@ class WebSweeper < ActionController::Caching::Sweeper
include CacheSweepingHelper include CacheSweepingHelper
observe Web, Page observe Web, Page, WikiFile
def after_save(record) def after_save(record)
if record.is_a?(Web) if record.is_a?(Web)
web = record web = record
web.pages.each { |page| expire_cached_page(web, page.name) } web.pages.each { |page| expire_cached_page(web, page.name) }
expire_cached_summary_pages(web) expire_cached_summary_pages(web)
elsif record.is_a?(WikiFile)
record.web.pages_that_link_to(record.file_name).each do |page|
expire_cached_page(record.web, page)
end
expire_cached_summary_pages(record.web)
end end
end end
@ -25,9 +30,11 @@ class WebSweeper < ActionController::Caching::Sweeper
def after_destroy(record) def after_destroy(record)
if record.is_a?(Web) if record.is_a?(Web)
expire_cached_summary_pages(record) expire_cached_summary_pages(record)
else elsif record.is_a?(Page)
expire_cached_page(record.web, record.name) expire_cached_page(record.web, record.name)
expire_cached_summary_pages(record.web) expire_cached_summary_pages(record.web)
else
expire_cached_summary_pages(record.web)
end end
end end

View file

@ -8,7 +8,7 @@ class WikiController < ApplicationController
before_filter :load_page before_filter :load_page
before_filter :dnsbl_check, :only => [:edit, :new, :save, :export_html, :export_markup] before_filter :dnsbl_check, :only => [:edit, :new, :save, :export_html, :export_markup]
caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, caches_action :show, :published, :authors, :tex, :s5, :print, :recently_revised, :list, :file_list,
:atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) } :atom_with_content, :atom_with_headlines, :if => Proc.new { |c| c.send(:do_caching?) }
cache_sweeper :revision_sweeper cache_sweeper :revision_sweeper

View file

@ -20,7 +20,7 @@
<a href="<%= url_for :web => @web.address, :action => 'files', <a href="<%= url_for :web => @web.address, :action => 'files',
:id => file.file_name %>"><%= file.file_name%></a> (<%= file.created_at.asctime %>) <span class="linked"><%= "Linked to by: " unless :id => file.file_name %>"><%= file.file_name%></a> (<%= file.created_at.asctime %>) <span class="linked"><%= "Linked to by: " unless
@web.pages_that_link_to(file.file_name).empty? -%> @web.pages_that_link_to(file.file_name).empty? -%>
<%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to referring_page }.join(", ") %></span> <%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %></span>
</li> </li>
<%- end -%> <%- end -%>
</ul> </ul>

View file

@ -20,6 +20,7 @@ ActionController::Routing::Routes.draw do |map|
connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category' connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category'
connect_to_web map, ':web/file/delete/:id', :controller => 'file', :action => 'delete', :requirements => {:id => /[-._\w]+/}, :id => nil connect_to_web map, ':web/file/delete/:id', :controller => 'file', :action => 'delete', :requirements => {:id => /[-._\w]+/}, :id => nil
connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil
connect_to_web map, ':web/file_list/:sort_order', :controller => 'wiki', :action => 'file_list', :sort_order => nil
connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import' connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import'
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login' connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'
connect_to_web map, ':web/web_list', :controller => 'wiki', :action => 'web_list' connect_to_web map, ':web/web_list', :controller => 'wiki', :action => 'web_list'