mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Mute log info coming from the local_cache strategy
This commit is contained in:
parent
16a48a95e3
commit
987d501182
4 changed files with 33 additions and 5 deletions
|
@ -115,6 +115,13 @@ module ActiveSupport
|
|||
self
|
||||
end
|
||||
|
||||
def mute
|
||||
previous_silence, @silence = defined?(@silence) && @silence, true
|
||||
yield
|
||||
ensure
|
||||
@silence = previous_silence
|
||||
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.
|
||||
#
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'active_support/core_ext/object/duplicable'
|
||||
|
||||
module ActiveSupport
|
||||
module Cache
|
||||
# A cache store implementation which stores everything into memory in the
|
||||
|
|
|
@ -44,7 +44,7 @@ module ActiveSupport
|
|||
nil
|
||||
elsif value.nil?
|
||||
value = super
|
||||
local_cache.write(key, value || NULL) if local_cache
|
||||
local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
|
||||
value.duplicable? ? value.dup : value
|
||||
else
|
||||
# forcing the value to be immutable
|
||||
|
@ -54,12 +54,12 @@ module ActiveSupport
|
|||
|
||||
def write(key, value, options = nil)
|
||||
value = value.to_s if respond_to?(:raw?) && raw?(options)
|
||||
local_cache.write(key, value || NULL) if local_cache
|
||||
local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
|
||||
super
|
||||
end
|
||||
|
||||
def delete(key, options = nil)
|
||||
local_cache.write(key, NULL) if local_cache
|
||||
local_cache.mute { local_cache.write(key, NULL) } if local_cache
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ module ActiveSupport
|
|||
|
||||
def increment(key, amount = 1)
|
||||
if value = super
|
||||
local_cache.write(key, value.to_s) if local_cache
|
||||
local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
|
||||
value
|
||||
else
|
||||
nil
|
||||
|
@ -85,7 +85,7 @@ module ActiveSupport
|
|||
|
||||
def decrement(key, amount = 1)
|
||||
if value = super
|
||||
local_cache.write(key, value.to_s) if local_cache
|
||||
local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
|
||||
value
|
||||
else
|
||||
nil
|
||||
|
|
|
@ -342,3 +342,22 @@ uses_memcached 'memcached backed store' do
|
|||
include CacheStoreBehavior
|
||||
end
|
||||
end
|
||||
|
||||
class CacheStoreLoggerTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
|
||||
|
||||
@buffer = StringIO.new
|
||||
@cache.logger = Logger.new(@buffer)
|
||||
end
|
||||
|
||||
def test_logging
|
||||
@cache.fetch('foo') { 'bar' }
|
||||
assert @buffer.string.present?
|
||||
end
|
||||
|
||||
def test_mute_logging
|
||||
@cache.mute { @cache.fetch('foo') { 'bar' } }
|
||||
assert @buffer.string.blank?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue