diff options
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 24 |
2 files changed, 19 insertions, 7 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 99d7192a9e..3408233b66 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -628,7 +628,7 @@ class FragmentCachingTest < ActionController::TestCase def test_fragment_for_logging fragment_computed = false - ActiveSupport::Orchestra.queue.expects(:publish).times(4) + ActiveSupport::Orchestra.queue.expects(:publish).times(2) buffer = 'generated till now -> ' @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index dfd53462af..a2717499e7 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -105,7 +105,7 @@ module ActiveSupport # cache.write("city", "Duckburgh") # cache.read("city") # => "Duckburgh" class Store - cattr_accessor :logger + cattr_accessor :logger, :instance_writter => false attr_reader :silence alias :silence? :silence @@ -122,6 +122,15 @@ module ActiveSupport @silence = previous_silence end + # Set to true if cache stores should be instrumented. By default is false. + def self.instrument=(boolean) + Thread.current[:instrument_cache_store] = boolean + end + + def self.instrument + Thread.current[:instrument_cache_store] || false + end + # Fetches data from the cache, using the given key. If there is data in # the cache with the given key, then that data is returned. # @@ -242,12 +251,15 @@ module ActiveSupport end def instrument(operation, key, options, &block) - payload = { :key => key } - payload.merge!(options) if options.is_a?(Hash) + log(operation, key, options) - # Cache events should be logged or not? - # log(operation, key, options) - ActiveSupport::Orchestra.instrument(:"cache_#{operation}", payload, &block) + if self.class.instrument + payload = { :key => key } + payload.merge!(options) if options.is_a?(Hash) + ActiveSupport::Orchestra.instrument(:"cache_#{operation}", payload, &block) + else + yield + end end def log(operation, key, options) |