1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Instrument cache store events only if required.

This commit is contained in:
José Valim 2009-10-09 08:22:42 -03:00
parent af0d1fa892
commit 8f59d7a8d8
2 changed files with 19 additions and 7 deletions

View file

@ -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 }

View file

@ -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)