diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 672215cc61d2a361447b39d37eadccceaa87a3b9..6f7f27fb5b91b6bb66ef5d43aaba3a4679f0e3fe 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -54,14 +54,14 @@ def self.append_features(base) #: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 @@ def caches_page(*actions) 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 @@ def expire_pages(*options) 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 @@ def cache_sweeper(*sweepers) end end end -end \ No newline at end of file +end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index e5fb9ade29fc794cc2d6ca9dd1973e4302de30d8..8746017245cd0b852440fd8ca5930a7bf58a739e 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added rewrite rules to deal with caching to public/.htaccess + * Added the option to specify a controller name to "generate scaffold" and made the default controller name the plural form of the model. * Added that rake clone_structure_to_test, db_structure_dump, and purge_test_database tasks now pick up the source database to use from diff --git a/railties/configs/apache.conf b/railties/configs/apache.conf index 592c7ef155104e2f1039c810443923a19cc3a6e4..5548292f8d5f3a64252ab5f894fad2693a863f27 100755 --- a/railties/configs/apache.conf +++ b/railties/configs/apache.conf @@ -12,22 +12,48 @@ RewriteBase /dispatch.cgi # Enable this rewrite rule to point to the controller/action that should serve root. # RewriteRule ^$ /controller/action [R] +# +# no query string? +RewriteCond %{QUERY_STRING} ^$ + +# no POST method? +RewriteCond %{REQUEST_METHOD} !^POST$ [NC] + +# Request filename is a directory? +RewriteCond %{REQUEST_FILENAME} -d + +# Request filename + '/index' is a file? +RewriteCond %{REQUEST_FILENAME}/index -f + +# Rewrite to request filename + '/index' and finish +RewriteRule ^(.*)/?$ $1/index [QSA,L] + +# no query string? +RewriteCond %{QUERY_STRING} ^$ + +# no POST method? +RewriteCond %{REQUEST_METHOD} !^POST$ [NC] + +# Request filename is a file? +RewriteCond %{REQUEST_FILENAME} -f + +# Finish rewriting +RewriteRule .* - [L] + +# Set default type of cached files to text/html +DefaultType text/html +# + # Add missing slash RewriteRule ^([-_a-zA-Z0-9]+)$ /$1/ [R] # Default rewriting rules. -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ ?controller=$1&action=$2&id=$3 [QSA,L] -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ ?controller=$1&action=$2 [QSA,L] -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/$ ?controller=$1&action=index [QSA,L] -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ ?module=$1&controller=$2&action=$3&id=$4 [QSA,L] -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ ?module=$1&controller=$2&action=$3 [QSA,L] -RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/$ ?module=$1&controller=$2&action=index [QSA,L] # You can also point these error messages to a controller/action