aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMichael Grosser <michael@grosser.it>2015-11-05 21:24:22 -0800
committerMichael Grosser <michael@grosser.it>2015-11-07 08:38:01 -0800
commite401a6bb251d382901d0e4e80b09545b29b16a89 (patch)
tree41f9d6b0cbb4079e5be55e0c16366ea6ae589a0d /activesupport
parentf036eacd6c9150e20e262568f9ee9897a8bad74f (diff)
downloadrails-e401a6bb251d382901d0e4e80b09545b29b16a89.tar.gz
rails-e401a6bb251d382901d0e4e80b09545b29b16a89.tar.bz2
rails-e401a6bb251d382901d0e4e80b09545b29b16a89.zip
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
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb14
-rw-r--r--activesupport/test/caching_test.rb11
2 files changed, 14 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index 4e2d3e9875..d521061004 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -48,10 +48,6 @@ module ActiveSupport
@data.clear
end
- def fetch(*args, &block)
- @data.fetch(*args, &block)
- end
-
def read_entry(key, options)
@data[key]
end
@@ -64,6 +60,10 @@ module ActiveSupport
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 @@ module ActiveSupport
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
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 94e73b6df3..3629f5e64b 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -633,6 +633,13 @@ module LocalCacheBehavior
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 @@ class CacheStoreLoggerTest < ActiveSupport::TestCase
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?