aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/caching/actions.rb
diff options
context:
space:
mode:
authorrick <technoweenie@gmail.com>2008-06-19 09:59:36 -0700
committerrick <technoweenie@gmail.com>2008-06-19 09:59:36 -0700
commit10c581a6deed66e8b62de6e7a3621a63de90baad (patch)
tree588ceb1118761602caa8ccf248dd08d59f33896c /actionpack/lib/action_controller/caching/actions.rb
parent64637da284ed4685591c178202ee103e6bee71cf (diff)
parent81025b5808886289f54d698f73f4199c99223e7e (diff)
downloadrails-10c581a6deed66e8b62de6e7a3621a63de90baad.tar.gz
rails-10c581a6deed66e8b62de6e7a3621a63de90baad.tar.bz2
rails-10c581a6deed66e8b62de6e7a3621a63de90baad.zip
fix merge
Diffstat (limited to 'actionpack/lib/action_controller/caching/actions.rb')
-rw-r--r--actionpack/lib/action_controller/caching/actions.rb41
1 files changed, 29 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb
index c4b0a97a33..65a36f7f98 100644
--- a/actionpack/lib/action_controller/caching/actions.rb
+++ b/actionpack/lib/action_controller/caching/actions.rb
@@ -67,10 +67,10 @@ module ActionController #:nodoc:
if options[:action].is_a?(Array)
options[:action].dup.each do |action|
- expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action })))
+ expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action }), false))
end
else
- expire_fragment(ActionCachePath.path_for(self, options))
+ expire_fragment(ActionCachePath.path_for(self, options, false))
end
end
@@ -125,16 +125,24 @@ module ActionController #:nodoc:
attr_reader :path, :extension
class << self
- def path_for(controller, options)
- new(controller, options).path
+ def path_for(controller, options, infer_extension=true)
+ new(controller, options, infer_extension).path
end
end
-
- def initialize(controller, options = {})
- @extension = extract_extension(controller.request.path)
+
+ # When true, infer_extension will look up the cache path extension from the request's path & format.
+ # This is desirable when reading and writing the cache, but not when expiring the cache - expire_action should expire the same files regardless of the request format.
+ def initialize(controller, options = {}, infer_extension=true)
+ if infer_extension and options.is_a? Hash
+ request_extension = extract_extension(controller.request)
+ options = options.reverse_merge(:format => request_extension)
+ end
path = controller.url_for(options).split('://').last
normalize!(path)
- add_extension!(path, @extension)
+ if infer_extension
+ @extension = request_extension
+ add_extension!(path, @extension)
+ end
@path = URI.unescape(path)
end
@@ -144,13 +152,22 @@ module ActionController #:nodoc:
end
def add_extension!(path, extension)
- path << ".#{extension}" if extension
+ path << ".#{extension}" if extension and !path.ends_with?(extension)
end
-
- def extract_extension(file_path)
+
+ def extract_extension(request)
# Don't want just what comes after the last '.' to accommodate multi part extensions
# such as tar.gz.
- file_path[/^[^.]+\.(.+)$/, 1]
+ extension = request.path[/^[^.]+\.(.+)$/, 1]
+
+ # If there's no extension in the path, check request.format
+ if extension.nil?
+ extension = request.format.to_sym.to_s
+ if extension=='all'
+ extension = nil
+ end
+ end
+ extension
end
end
end