Skip to content

Commit

Permalink
Merge pull request #32315 from huacnlee/fix/local-cache-read-multi-en…
Browse files Browse the repository at this point in the history
…try-return

Fix Cache `read_multi` with local_cache bug, should returns raw value, not `ActiveSupport::Cache::Entry` instance.
  • Loading branch information
rafaelfranca committed Mar 22, 2018
2 parents e26424a + 4e13a36 commit 57e1453
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -55,7 +55,14 @@ def read_entry(key, options)
end

def read_multi_entries(keys, options)
Hash[keys.map { |name| [name, read_entry(name, options)] }.keep_if { |_name, value| value }]
values = {}

keys.each do |name|
entry = read_entry(name, options)
values[name] = entry.value if entry
end

values
end

def write_entry(key, value, options)
Expand Down
12 changes: 12 additions & 0 deletions activesupport/test/cache/behaviors/local_cache_behavior.rb
Expand Up @@ -129,6 +129,18 @@ def test_local_cache_of_fetch_multi
end
end

def test_local_cache_of_read_multi
@cache.with_local_cache do
@cache.write("foo", "foo", raw: true)
@cache.write("bar", "bar", raw: true)
values = @cache.read_multi("foo", "bar")
assert_equal "foo", @cache.read("foo")
assert_equal "bar", @cache.read("bar")
assert_equal "foo", values["foo"]
assert_equal "bar", values["bar"]
end
end

def test_middleware
app = lambda { |env|
result = @cache.write("foo", "bar")
Expand Down

0 comments on commit 57e1453

Please sign in to comment.