<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -46,33 +46,39 @@ module ActionController
     # in the template, as 'when_fragment_expired' will expire the fragment for you.
     module TimedFragment
     
-      def self.included(base) # :nodoc:     
-        base.class_eval do 
-          alias_method :cache_erb_fragment_without_expiry, :cache_erb_fragment
-          alias_method :cache_erb_fragment, :cache_erb_fragment_with_expiry
-        end      
-      end
-            
-      def cache_erb_fragment_with_expiry(block, name = {}, options = nil, expiry = nil)
+      def cache_erb_fragment(block, name = {}, options = nil, expiry = nil)
         unless perform_caching then block.call; return end
 
-        if expiry &amp;&amp; fragment_expired?(name)
+        fragment = get_fragment(name)
+        if expiry &amp;&amp; !fragment
           expire_and_write_meta(name, expiry)  
         end
-        
-        cache_erb_fragment_without_expiry(block, name, options)          
+
+        buffer = eval(&quot;_erbout&quot;, block.binding)
+
+        if fragment
+          buffer.concat(fragment)
+        else
+          pos = buffer.length
+          block.call
+          write_fragment(name, buffer[pos..-1], options)
+        end
+  
       end
     
       def expiry_time(name)
         read_meta_fragment(name)
       end
     
-      def fragment_expired?(name)
-        return true unless read_fragment(name)
+      def get_fragment(name)
+      	return fragments[name] if fragments[name]
+      	fragment = read_fragment(name)
+        return nil unless fragment
+        fragments[name] = fragment
         expires = expiry_time(name)
-        expires.nil? || expires &lt; Time.now
+        return expires &amp;&amp; expires &gt; Time.now ? fragment : nil
       end
-    
+
       def read_meta_fragment(name)
         YAML.load(read_fragment(meta_fragment_key(name))) rescue nil
       end    
@@ -86,8 +92,7 @@ module ActionController
       end
     
       def when_fragment_expired(name, expiry=nil)
-        return unless fragment_expired? name
-        
+      	return if get_fragment( name )
         yield
         expire_and_write_meta(name, expiry)
       end
@@ -97,6 +102,9 @@ module ActionController
         write_meta_fragment(name, expiry) if expiry
       end
     
+      def fragments
+      	@fragments ||= {}
+      end
     end
   end
 end
@@ -120,4 +128,4 @@ module ActionView
 end
 
 ActionController::Base.send :include, ActionController::Caching::TimedFragment
-ActionView::Base.send(:include, ActionView::Helpers::TimedFragmentCacheHelper)
\ No newline at end of file
+ActionView::Base.send(:include, ActionView::Helpers::TimedFragmentCacheHelper)</diff>
      <filename>lib/timed_fragment_cache.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e4eafd6ac65358bee775ddcf39899a807d3a0a51</id>
    </parent>
  </parents>
  <author>
    <name>rlivsey</name>
    <email>rlivsey@179e805f-c116-0410-8f81-92903350386d</email>
  </author>
  <url>http://github.com/veilleperso/timed_fragment_cache/commit/682f7b9e2f3fd3b849210d719e1277e2287f35f4</url>
  <id>682f7b9e2f3fd3b849210d719e1277e2287f35f4</id>
  <committed-date>2007-08-13T06:47:08-07:00</committed-date>
  <authored-date>2007-08-13T06:47:08-07:00</authored-date>
  <message>Applied patch by Marek Janukowicz to stop race condition

git-svn-id: http://svn.livsey.org/plugins/timed_fragment_cache@45 179e805f-c116-0410-8f81-92903350386d</message>
  <tree>f970307ee084d575788c906042609f5bc10c3f41</tree>
  <committer>
    <name>rlivsey</name>
    <email>rlivsey@179e805f-c116-0410-8f81-92903350386d</email>
  </committer>
</commit>
