aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-05-27 16:38:02 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-05-27 16:38:02 +0000
commitd3b5db8919c61243c45ebd09254de20f4aa0cf1d (patch)
tree4da6169466bdd233002abce12c49d292f4dd0ab2 /actionpack
parentcd599aad715679355d16caf3585901034fca5a87 (diff)
downloadrails-d3b5db8919c61243c45ebd09254de20f4aa0cf1d.tar.gz
rails-d3b5db8919c61243c45ebd09254de20f4aa0cf1d.tar.bz2
rails-d3b5db8919c61243c45ebd09254de20f4aa0cf1d.zip
Added custom path cache_page/expire_page parameters in addition to the options hashes [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6868 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG6
-rw-r--r--actionpack/lib/action_controller/caching.rb22
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/controller/caching_test.rb24
4 files changed, 49 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 770b87f085..3151f05077 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,11 @@
*SVN*
+* Added custom path cache_page/expire_page parameters in addition to the options hashes [DHH]. Example:
+
+ def index
+ caches_page(response.body, "/index.html")
+ end
+
* Action Caching speedup. #8231 [skaes]
* Wordsmith resources documentation. #8484 [marclove]
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index ddb36c5b8e..f77cf207f5 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -118,12 +118,17 @@ module ActionController #:nodoc:
# expire_page :controller => "lists", :action => "show"
def expire_page(options = {})
return unless perform_caching
- if options[:action].is_a?(Array)
- options[:action].dup.each do |action|
- self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :action => action)))
+
+ if options.is_a?(Hash)
+ if options[:action].is_a?(Array)
+ options[:action].dup.each do |action|
+ self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :action => action)))
+ end
+ else
+ self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true)))
end
else
- self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true)))
+ self.class.expire_page(options)
end
end
@@ -132,7 +137,14 @@ module ActionController #:nodoc:
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
def cache_page(content = nil, options = {})
return unless perform_caching && caching_allowed
- self.class.cache_page(content || response.body, url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format])))
+
+ if options.is_a?(Hash)
+ path = url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))
+ else
+ path = options
+ end
+
+ self.class.cache_page(content || response.body, path)
end
private
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 3c576f3d20..2d7b5f2af6 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -9,6 +9,8 @@ require 'action_controller'
require 'action_controller/cgi_ext'
require 'action_controller/test_process'
+require 'ruby-debug'
+
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index dcbe27622d..0dc73472cf 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -25,6 +25,16 @@ class PageCachingTestController < ActionController::Base
def not_found
head :not_found
end
+
+ def custom_path
+ render :text => "Super soaker"
+ cache_page("Super soaker", "/index.html")
+ end
+
+ def expire_custom_path
+ expire_page("/index.html")
+ head :ok
+ end
end
class PageCachingTest < Test::Unit::TestCase
@@ -69,6 +79,19 @@ class PageCachingTest < Test::Unit::TestCase
assert_page_cached :ok, "get with ok status should have been cached"
end
+ def test_should_cache_with_custom_path
+ get :custom_path
+ assert File.exist?("#{FILE_STORE_PATH}/index.html")
+ end
+
+ def test_should_expire_cache_with_custom_path
+ get :custom_path
+ assert File.exist?("#{FILE_STORE_PATH}/index.html")
+
+ get :expire_custom_path
+ assert !File.exist?("#{FILE_STORE_PATH}/index.html")
+ end
+
[:ok, :no_content, :found, :not_found].each do |status|
[:get, :post, :put, :delete].each do |method|
unless method == :get and status == :ok
@@ -96,6 +119,7 @@ class PageCachingTest < Test::Unit::TestCase
end
end
+
class ActionCachingTestController < ActionController::Base
caches_action :index
caches_action :show, :cache_path => 'http://test.host/custom/show'