diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 13:22:58 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-15 13:22:58 +0000 |
commit | c755b29a862c7da91f30a7c68ac98cfdc79cfbf5 (patch) | |
tree | e602f75aa56a6a076f1d4a3657e143e49c706a1c /actionpack/lib/action_controller | |
parent | 4a0695996f78c6fd330f1961d450367fc8fa5406 (diff) | |
download | rails-c755b29a862c7da91f30a7c68ac98cfdc79cfbf5.tar.gz rails-c755b29a862c7da91f30a7c68ac98cfdc79cfbf5.tar.bz2 rails-c755b29a862c7da91f30a7c68ac98cfdc79cfbf5.zip |
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
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/caching.rb | 22 |
1 files changed, 17 insertions, 5 deletions
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 |