<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -64,10 +64,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 =&gt; action })))
+              expire_fragment(ActionCachePath.path_for(self, options.merge({ :action =&gt; action }), false))
             end
           else
-            expire_fragment(ActionCachePath.path_for(self, options))
+            expire_fragment(ActionCachePath.path_for(self, options, false))
           end
         end
 
@@ -111,16 +111,24 @@ module ActionController #:nodoc:
         attr_reader :path, :extension
 
         class &lt;&lt; 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 &amp; 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 =&gt; 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
 
@@ -130,13 +138,22 @@ module ActionController #:nodoc:
           end
 
           def add_extension!(path, extension)
-            path &lt;&lt; &quot;.#{extension}&quot; if extension
+            path &lt;&lt; &quot;.#{extension}&quot; 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</diff>
      <filename>actionpack/lib/action_controller/caching/actions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -186,6 +186,10 @@ class ActionCachingTestController &lt; ActionController::Base
     expire_action :controller =&gt; 'action_caching_test', :action =&gt; 'index'
     render :nothing =&gt; true
   end
+  def expire_xml
+    expire_action :controller =&gt; 'action_caching_test', :action =&gt; 'index', :format =&gt; 'xml'
+    render :nothing =&gt; true
+  end
 end
 
 class MockTime &lt; Time
@@ -211,6 +215,7 @@ class ActionCachingMockController
     mocked_path = @mock_path
     Object.new.instance_eval(&lt;&lt;-EVAL)
       def path; '#{@mock_path}' end
+      def format; 'all' end
       self
     EVAL
   end
@@ -311,6 +316,20 @@ class ActionCacheTest &lt; Test::Unit::TestCase
     assert_equal new_cached_time, @response.body
   end
 
+  def test_cache_expiration_isnt_affected_by_request_format
+    get :index
+    cached_time = content_to_cache
+    reset!
+
+    @request.set_REQUEST_URI &quot;/action_caching_test/expire.xml&quot;
+    get :expire, :format =&gt; :xml
+    reset!
+
+    get :index
+    new_cached_time = content_to_cache
+    assert_not_equal cached_time, @response.body
+  end
+
   def test_cache_is_scoped_by_subdomain
     @request.host = 'jamis.hostname.com'
     get :index
@@ -355,11 +374,35 @@ class ActionCacheTest &lt; Test::Unit::TestCase
   end
 
   def test_xml_version_of_resource_is_treated_as_different_cache
-    @mock_controller.mock_url_for = 'http://example.org/posts/'
-    @mock_controller.mock_path    = '/posts/index.xml'
-    path_object = @path_class.new(@mock_controller, {})
-    assert_equal 'xml', path_object.extension
-    assert_equal 'example.org/posts/index.xml', path_object.path
+    with_routing do |set|
+      ActionController::Routing::Routes.draw do |map|
+        map.connect ':controller/:action.:format'
+        map.connect ':controller/:action'
+      end
+
+      get :index, :format =&gt; 'xml'
+      cached_time = content_to_cache
+      assert_equal cached_time, @response.body
+      assert fragment_exist?('hostname.com/action_caching_test/index.xml')
+      reset!
+
+      get :index, :format =&gt; 'xml'
+      assert_equal cached_time, @response.body
+      assert_equal 'application/xml', @response.content_type
+      reset!
+
+      @request.env['HTTP_ACCEPT'] = &quot;application/xml&quot;
+      get :index
+      assert_equal cached_time, @response.body
+      assert_equal 'application/xml', @response.content_type
+      reset!
+
+      get :expire_xml
+      reset!
+
+      get :index, :format =&gt; 'xml'
+      assert_not_equal cached_time, @response.body
+    end
   end
 
   def test_correct_content_type_is_returned_for_cache_hit</diff>
      <filename>actionpack/test/controller/caching_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a6e79083273dfb1a62aa8ff02db07454c65729ff</id>
    </parent>
  </parents>
  <author>
    <name>Jonathan del Strother</name>
    <email>jon.delStrother@bestbefore.tv</email>
  </author>
  <url>http://github.com/jdelStrother/rails/commit/a814a2b7ccf0baa56b1f8bfbb12d1bb5bf653ec8</url>
  <id>a814a2b7ccf0baa56b1f8bfbb12d1bb5bf653ec8</id>
  <committed-date>2008-05-31T17:14:03-07:00</committed-date>
  <authored-date>2008-03-06T03:50:44-08:00</authored-date>
  <message>Improve ActionCaching's format-handling

Make ActionCaching more aware of different mimetype formats.
It will now use request.format to look up the cache type, in addition to the path extension.
When expiring caches, the request format no longer affects which cache is expired.</message>
  <tree>b6a3bfd715e8259266acb7e96bb68a9070a6b202</tree>
  <committer>
    <name>Jonathan del Strother</name>
    <email>jon.delStrother@bestbefore.tv</email>
  </committer>
</commit>
