Skip to content
This repository
Browse code

write_fragment returns content if caching is disabled [#846 state:res…

…olved]
  • Loading branch information...
commit 20d6fdd2567b44fc7de9768a6dedd50d2ea9c4ce 1 parent cd1a9ed
Joshua Peek authored November 22, 2008
22  actionpack/lib/action_controller/caching/fragments.rb
@@ -10,23 +10,23 @@ module Caching
10 10
     #     <%= render :partial => "topic", :collection => Topic.find(:all) %>
11 11
     #   <% end %>
12 12
     #
13  
-    # This cache will bind to the name of the action that called it, so if this code was part of the view for the topics/list action, you would 
14  
-    # be able to invalidate it using <tt>expire_fragment(:controller => "topics", :action => "list")</tt>. 
15  
-    # 
16  
-    # This default behavior is of limited use if you need to cache multiple fragments per action or if the action itself is cached using 
  13
+    # This cache will bind to the name of the action that called it, so if this code was part of the view for the topics/list action, you would
  14
+    # be able to invalidate it using <tt>expire_fragment(:controller => "topics", :action => "list")</tt>.
  15
+    #
  16
+    # This default behavior is of limited use if you need to cache multiple fragments per action or if the action itself is cached using
17 17
     # <tt>caches_action</tt>, so we also have the option to qualify the name of the cached fragment with something like:
18 18
     #
19 19
     #   <% cache(:action => "list", :action_suffix => "all_topics") do %>
20 20
     #
21  
-    # That would result in a name such as "/topics/list/all_topics", avoiding conflicts with the action cache and with any fragments that use a 
22  
-    # different suffix. Note that the URL doesn't have to really exist or be callable - the url_for system is just used to generate unique 
23  
-    # cache names that we can refer to when we need to expire the cache. 
24  
-    # 
  21
+    # That would result in a name such as "/topics/list/all_topics", avoiding conflicts with the action cache and with any fragments that use a
  22
+    # different suffix. Note that the URL doesn't have to really exist or be callable - the url_for system is just used to generate unique
  23
+    # cache names that we can refer to when we need to expire the cache.
  24
+    #
25 25
     # The expiration call for this example is:
26  
-    # 
  26
+    #
27 27
     #   expire_fragment(:controller => "topics", :action => "list", :action_suffix => "all_topics")
28 28
     module Fragments
29  
-      # Given a key (as described in <tt>expire_fragment</tt>), returns a key suitable for use in reading, 
  29
+      # Given a key (as described in <tt>expire_fragment</tt>), returns a key suitable for use in reading,
30 30
       # writing, or expiring a cached fragment. If the key is a hash, the generated key is the return
31 31
       # value of url_for on that hash (without the protocol). All keys are prefixed with "views/" and uses
32 32
       # ActiveSupport::Cache.expand_cache_key for the expansion.
@@ -50,7 +50,7 @@ def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
50 50
 
51 51
       # Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
52 52
       def write_fragment(key, content, options = nil)
53  
-        return unless cache_configured?
  53
+        return content unless cache_configured?
54 54
 
55 55
         key = fragment_cache_key(key)
56 56
 
2  actionpack/test/controller/caching_test.rb
@@ -527,7 +527,7 @@ def test_write_fragment_with_caching_enabled
527 527
   def test_write_fragment_with_caching_disabled
528 528
     assert_nil @store.read('views/name')
529 529
     ActionController::Base.perform_caching = false
530  
-    assert_equal nil, @controller.write_fragment('name', 'value')
  530
+    assert_equal 'value', @controller.write_fragment('name', 'value')
531 531
     assert_nil @store.read('views/name')
532 532
   end
533 533
 

0 notes on commit 20d6fdd

Please sign in to comment.
Something went wrong with that request. Please try again.