diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 3e3dc18263..5a064f8bea 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -21,7 +21,7 @@ module ActiveSupport expanded_cache_key = namespace ? "#{namespace}/" : "" if ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"] - expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/" + expanded_cache_key << "#{ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]}/" end expanded_cache_key << case @@ -36,16 +36,15 @@ module ActiveSupport expanded_cache_key end - class Store cattr_accessor :logger - def initialize + def threadsafe! + extend ThreadSafety end - def threadsafe! - @mutex = Mutex.new - self.class.send :include, ThreadSafety + def silence! + @silence = true self end @@ -110,29 +109,24 @@ module ActiveSupport nil end end - + private def log(operation, key, options) - logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !@logger_off + logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !@silence && !@logger_off end end - module ThreadSafety #:nodoc: - def read(key, options = nil) #:nodoc: - @mutex.synchronize { super } - end - - def write(key, value, options = nil) #:nodoc: - @mutex.synchronize { super } - end - - def delete(key, options = nil) #:nodoc: - @mutex.synchronize { super } + def self.extended(object) #:nodoc: + object.instance_variable_set(:@mutex, Mutex.new) end - def delete_matched(matcher, options = nil) #:nodoc: - @mutex.synchronize { super } + %w(read write delete delete_matched exist? increment decrement).each do |method| + module_eval <<-EOS, __FILE__, __LINE__ + def #{method}(*args) + @mutex.synchronize { super } + end + EOS end end end |