From c755b29a862c7da91f30a7c68ac98cfdc79cfbf5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 15 Jan 2005 13:22:58 +0000 Subject: Fixed page caching problems with saving cached file fails for the index action and that it shouldnt cache files with GET/POST parameters #462 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@407 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/caching.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 672215cc61..6f7f27fb5b 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -54,14 +54,14 @@ module ActionController #:nodoc: module ClassMethods def cache_page(content, path) return unless perform_caching - FileUtils.makedirs(File.dirname(page_cache_directory + path)) - File.open(page_cache_directory + path, "w+") { |f| f.write(content) } + FileUtils.makedirs(File.dirname(page_cache_path(path))) + File.open(page_cache_path(path), "w+") { |f| f.write(content) } logger.info "Cached page: #{path}" unless logger.nil? end def expire_page(path) return unless perform_caching - File.delete(page_cache_directory + path) if File.exists?(page_cache_directory + path) + File.delete(page_cache_path(path)) if File.exists?(page_cache_path(path)) logger.info "Expired page: #{path}" unless logger.nil? end @@ -71,6 +71,14 @@ module ActionController #:nodoc: class_eval "after_filter { |c| c.cache_page if c.action_name == '#{action}' }" end end + + def page_cache_path(path) + if path[-1,1] == '/' + page_cache_directory + path + '/index' + else + page_cache_directory + path + end + end end def expire_page(options = {}) @@ -94,9 +102,13 @@ module ActionController #:nodoc: end def cache_page(content = nil, options = {}) - return unless perform_caching + return unless perform_caching && caching_allowed self.class.cache_page(content || @response.body, url_for(options.merge({ :only_path => true }))) end + + def caching_allowed + !@request.method.post? and (@request.parameters.reject {|k, v| ['id', 'action', 'controller'].include?(k)}).empty? + end end # Action caching is similar to page caching by the fact that the entire output of the response is cached, but unlike page caching, @@ -348,4 +360,4 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end -- cgit v1.2.3