提交 e401a6bb 编写于 作者: M Michael Grosser

do not override fetch on local cache

fetch is supposed to behave differently, this was a mistake merged in

https://github.com/rails/rails/pull/22194
上级 f036eacd
......@@ -48,10 +48,6 @@ def clear(options = nil)
@data.clear
end
def fetch(*args, &block)
@data.fetch(*args, &block)
end
def read_entry(key, options)
@data[key]
end
......@@ -64,6 +60,10 @@ def write_entry(key, value, options)
def delete_entry(key, options)
!!@data.delete(key)
end
def fetch_entry(key, options = nil) # :nodoc:
@data.fetch(key) { @data[key] = yield }
end
end
# Use a local cache for the duration of block.
......@@ -103,11 +103,7 @@ def decrement(name, amount = 1, options = nil) # :nodoc:
protected
def read_entry(key, options) # :nodoc:
if cache = local_cache
cache.fetch(key) do
entry = super
cache.write_entry(key, entry, options)
entry
end
cache.fetch_entry(key) { super }
else
super
end
......
......@@ -633,6 +633,13 @@ def test_local_cache_of_read_nil
end
end
def test_local_cache_fetch
@cache.with_local_cache do
@cache.send(:local_cache).write 'foo', 'bar'
assert_equal 'bar', @cache.send(:local_cache).fetch('foo')
end
end
def test_local_cache_of_write_nil
@cache.with_local_cache do
assert @cache.write('foo', nil)
......@@ -1102,11 +1109,11 @@ def test_log_with_string_namespace
def test_log_with_proc_namespace
proc = Proc.new do
"proc_namespace"
end
end
@cache.fetch('foo', {:namespace => proc}) { 'bar' }
assert_match %r{proc_namespace:foo}, @buffer.string
end
def test_mute_logging
@cache.mute { @cache.fetch('foo') { 'bar' } }
assert @buffer.string.blank?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册