aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-10-09 08:22:42 -0300
committerJosé Valim <jose.valim@gmail.com>2009-10-15 18:19:24 -0300
commit8f59d7a8d8e736d7f4b6730020c197d008fb0779 (patch)
tree3a2bc6beef44025353b5d5834e6e40572095e90e /activesupport
parentaf0d1fa8920793a95fae456d1f5debdc50287eb3 (diff)
downloadrails-8f59d7a8d8e736d7f4b6730020c197d008fb0779.tar.gz
rails-8f59d7a8d8e736d7f4b6730020c197d008fb0779.tar.bz2
rails-8f59d7a8d8e736d7f4b6730020c197d008fb0779.zip
Instrument cache store events only if required.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/cache.rb24
1 files changed, 18 insertions, 6 deletions
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)