diff options
-rw-r--r-- | activesupport/lib/active_support/cache/strategy/local_cache.rb | 9 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index fe5bc82c30..e1da2be2d4 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -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) + entry end - entry else super end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 74ceff44f9..44e0eb9764 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -597,6 +597,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) |