Skip to content

Commit

Permalink
Fixes "Cached fragment hit" written to log even if fragment is not ca…
Browse files Browse the repository at this point in the history
…ched (Erik Andrejko) [#2917 state:resolved]
  • Loading branch information
wycats committed Aug 8, 2009
1 parent 0fbeaa9 commit efcfce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/caching/fragments.rb
Expand Up @@ -36,8 +36,8 @@ def fragment_cache_key(key)

def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
if perform_caching
if cache = read_fragment(name, options)
buffer.concat(cache)
if fragment_exist?(name,options)
buffer.concat(read_fragment(name, options))
else
pos = buffer.length
block.call
Expand Down
15 changes: 15 additions & 0 deletions actionpack/test/controller/caching_test.rb
Expand Up @@ -625,6 +625,21 @@ def test_fragment_for
assert !fragment_computed
assert_equal 'generated till now -> fragment content', buffer
end

def test_fragment_for_logging
fragment_computed = false

@controller.class.expects(:benchmark).with('Cached fragment exists?: views/expensive')
@controller.class.expects(:benchmark).with('Cached fragment miss: views/expensive')
@controller.class.expects(:benchmark).with('Cached fragment hit: views/expensive').never

buffer = 'generated till now -> '
@controller.fragment_for(buffer, 'expensive') { fragment_computed = true }

assert fragment_computed
assert_equal 'generated till now -> ', buffer
end

end

class FunctionalCachingController < ActionController::Base
Expand Down

0 comments on commit efcfce5

Please sign in to comment.