mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #22194 from grosser/grosser/read-nil
cache nil replies from backend cache so misses are fast too
This commit is contained in:
commit
cb67c81933
2 changed files with 14 additions and 3 deletions
|
@ -48,6 +48,10 @@ module ActiveSupport
|
|||
@data.clear
|
||||
end
|
||||
|
||||
def fetch(*args, &block)
|
||||
@data.fetch(*args, &block)
|
||||
end
|
||||
|
||||
def read_entry(key, options)
|
||||
@data[key]
|
||||
end
|
||||
|
@ -99,12 +103,11 @@ module ActiveSupport
|
|||
protected
|
||||
def read_entry(key, options) # :nodoc:
|
||||
if local_cache
|
||||
entry = local_cache.read_entry(key, options)
|
||||
unless entry
|
||||
local_cache.fetch(key) do
|
||||
entry = super
|
||||
local_cache.write_entry(key, entry, options)
|
||||
end
|
||||
entry
|
||||
end
|
||||
else
|
||||
super
|
||||
end
|
||||
|
|
|
@ -625,6 +625,14 @@ module LocalCacheBehavior
|
|||
end
|
||||
end
|
||||
|
||||
def test_local_cache_of_read_nil
|
||||
@cache.with_local_cache do
|
||||
assert_equal nil, @cache.read('foo')
|
||||
@cache.send(:bypass_local_cache) { @cache.write 'foo', 'bar' }
|
||||
assert_equal nil, @cache.read('foo')
|
||||
end
|
||||
end
|
||||
|
||||
def test_local_cache_of_write_nil
|
||||
@cache.with_local_cache do
|
||||
assert @cache.write('foo', nil)
|
||||
|
|
Loading…
Reference in a new issue