<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -98,6 +98,17 @@ module ActionController #:nodoc:
         end
       end
 
+      # Check if a cached fragment from the location signified by &lt;tt&gt;key&lt;/tt&gt; exists (see &lt;tt&gt;expire_fragment&lt;/tt&gt; for acceptable formats)
+      def fragment_exist?(key, options = nil)
+        return unless cache_configured?
+
+        key = fragment_cache_key(key)
+
+        self.class.benchmark &quot;Cached fragment exists?: #{key}&quot; do
+          cache_store.exist?(key, options)
+        end
+      end
+
       # Name can take one of three forms:
       # * String: This would normally take the form of a path like &quot;pages/45/notes&quot;
       # * Hash: Is treated as an implicit call to url_for, like { :controller =&gt; &quot;pages&quot;, :action =&gt; &quot;notes&quot;, :id =&gt; 45 }
@@ -124,4 +135,4 @@ module ActionController #:nodoc:
       end
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>actionpack/lib/action_controller/caching/fragments.rb</filename>
    </modified>
    <modified>
      <diff>@@ -232,7 +232,7 @@ class ActionCacheTest &lt; Test::Unit::TestCase
     get :index
     cached_time = content_to_cache
     assert_equal cached_time, @response.body
-    assert_cache_exists 'hostname.com/action_caching_test'
+    assert fragment_exist?('hostname.com/action_caching_test')
     reset!
 
     get :index
@@ -243,7 +243,7 @@ class ActionCacheTest &lt; Test::Unit::TestCase
     get :destroy
     cached_time = content_to_cache
     assert_equal cached_time, @response.body
-    assert_cache_does_not_exist 'hostname.com/action_caching_test/destroy'
+    assert !fragment_exist?('hostname.com/action_caching_test/destroy')
     reset!
 
     get :destroy
@@ -254,7 +254,7 @@ class ActionCacheTest &lt; Test::Unit::TestCase
     get :with_layout
     cached_time = content_to_cache
     assert_not_equal cached_time, @response.body
-    assert_cache_exists 'hostname.com/action_caching_test/with_layout'
+    assert fragment_exist?('hostname.com/action_caching_test/with_layout')
     reset!
 
     get :with_layout
@@ -266,14 +266,14 @@ class ActionCacheTest &lt; Test::Unit::TestCase
   def test_action_cache_conditional_options
     @request.env['HTTP_ACCEPT'] = 'application/json'
     get :index
-    assert_cache_does_not_exist 'hostname.com/action_caching_test'
+    assert !fragment_exist?('hostname.com/action_caching_test')
   end
 
   def test_action_cache_with_custom_cache_path
     get :show
     cached_time = content_to_cache
     assert_equal cached_time, @response.body
-    assert_cache_exists 'test.host/custom/show'
+    assert fragment_exist?('test.host/custom/show')
     reset!
 
     get :show
@@ -282,11 +282,11 @@ class ActionCacheTest &lt; Test::Unit::TestCase
 
   def test_action_cache_with_custom_cache_path_in_block
     get :edit
-    assert_cache_exists 'test.host/edit'
+    assert fragment_exist?('test.host/edit')
     reset!
 
     get :edit, :id =&gt; 1
-    assert_cache_exists 'test.host/1;edit'
+    assert fragment_exist?('test.host/1;edit')
   end
 
   def test_cache_expiration
@@ -395,18 +395,8 @@ class ActionCacheTest &lt; Test::Unit::TestCase
       @request.host = 'hostname.com'
     end
 
-    def assert_cache_exists(path)
-      full_path = cache_path(path)
-      assert File.exist?(full_path), &quot;#{full_path.inspect} does not exist.&quot;
-    end
-
-    def assert_cache_does_not_exist(path)
-      full_path = cache_path(path)
-      assert !File.exist?(full_path), &quot;#{full_path.inspect} should not exist.&quot;
-    end
-
-    def cache_path(path)
-      File.join(FILE_STORE_PATH, 'views', path + '.cache')
+    def fragment_exist?(path)
+      @controller.fragment_exist?(path)
     end
 
     def read_fragment(path)
@@ -450,6 +440,19 @@ class FragmentCachingTest &lt; Test::Unit::TestCase
     assert_nil @controller.read_fragment('name')
   end
 
+  def test_fragment_exist__with_caching_enabled
+    @store.write('views/name', 'value')
+    assert @controller.fragment_exist?('name')
+    assert !@controller.fragment_exist?('other_name')
+  end
+
+  def test_fragment_exist__with_caching_disabled
+    ActionController::Base.perform_caching = false
+    @store.write('views/name', 'value')
+    assert !@controller.fragment_exist?('name')
+    assert !@controller.fragment_exist?('other_name')
+  end
+
   def test_write_fragment__with_caching_enabled
     assert_nil @store.read('views/name')
     assert_equal 'value', @controller.write_fragment('name', 'value')
@@ -494,7 +497,6 @@ class FragmentCachingTest &lt; Test::Unit::TestCase
     assert_equal 'generated till now -&gt; ', buffer
   end
 
-
   def test_fragment_for
     @store.write('views/expensive', 'fragment content')
     fragment_computed = false</diff>
      <filename>actionpack/test/controller/caching_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -87,8 +87,12 @@ module ActiveSupport
 
       def delete_matched(matcher, options = nil)
         log(&quot;delete matched&quot;, matcher.inspect, options)
-      end       
-      
+      end
+
+      def exist?(key, options = nil)
+        log(&quot;exist?&quot;, key, options)
+      end
+
       def increment(key, amount = 1)
         log(&quot;incrementing&quot;, key, amount)
         if num = read(key)</diff>
      <filename>activesupport/lib/active_support/cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -40,13 +40,18 @@ module ActiveSupport
         end
       end
 
+      def exist?(name, options = nil)
+        super
+        File.exist?(real_file_path(name))
+      end
+
       private
         def real_file_path(name)
           '%s/%s.cache' % [@cache_path, name.gsub('?', '.').gsub(':', '.')]
         end
 
         def ensure_cache_path(path)
-          FileUtils.makedirs(path) unless File.exists?(path)
+          FileUtils.makedirs(path) unless File.exist?(path)
         end
 
         def search_dir(dir, &amp;callback)</diff>
      <filename>activesupport/lib/active_support/cache/file_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -48,7 +48,13 @@ module ActiveSupport
       rescue MemCache::MemCacheError =&gt; e
         logger.error(&quot;MemCacheError (#{e}): #{e.message}&quot;)
         false
-      end              
+      end
+
+      def exist?(key, options = nil)
+        # Doesn't call super, cause exist? in memcache is in fact a read
+        # But who cares? Reading is very fast anyway
+        !read(key, options).nil?
+      end
 
       def increment(key, amount = 1)       
         log(&quot;incrementing&quot;, key, amount)</diff>
      <filename>activesupport/lib/active_support/cache/mem_cache_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,12 @@ module ActiveSupport
         super
         @data.delete_if { |k,v| k =~ matcher }
       end
-      
+
+      def exist?(name,options = nil)
+        super
+        @data.has_key?(name)
+      end
+
       def clear
         @data.clear
       end</diff>
      <filename>activesupport/lib/active_support/cache/memory_store.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>17d1319c480e58e28641b243da50ae5e5eab89dc</id>
    </parent>
  </parents>
  <author>
    <name>Jos&#233; Valim</name>
    <email>jose.valim@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/99860b72aebe0348f41e82d4710343498d89a84b</url>
  <id>99860b72aebe0348f41e82d4710343498d89a84b</id>
  <committed-date>2008-05-19T02:38:59-07:00</committed-date>
  <authored-date>2008-05-16T10:10:30-07:00</authored-date>
  <message>Add fragment_exist? and exist? methods to cache stores. [#203 state:resolved]

Signed-off-by: Pratik Naik &lt;pratiknaik@gmail.com&gt;</message>
  <tree>56457862ab6ce523cfb7d6dacd9f38655ab8c715</tree>
  <committer>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
