Skip to content

Commit

Permalink
fix LocalCache#read_multi_entries
Browse files Browse the repository at this point in the history
In cache stores prepending `LocalCache`, serialized `Entry`
instances are stored in `LocalCache::LocalStore`. This
speeds up hot key lookups without a network roundtrip in a
context of a single given request.

However, with these entries being stored in their serialized
form, `#read_multi_entries` returns them directly to cache
consumers.

Instead, we will now deserialize these entries first.
  • Loading branch information
avalanche123 committed Feb 9, 2022
1 parent 4d4497b commit 3933a41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -123,6 +123,9 @@ def read_multi_entries(keys, **options)
return super unless local_cache

local_entries = local_cache.read_multi_entries(keys)
local_entries.transform_values! do |payload|
deserialize_entry(payload).value
end
missed_keys = keys - local_entries.keys

if missed_keys.any?
Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/cache/behaviors/local_cache_behavior.rb
Expand Up @@ -286,4 +286,13 @@ def test_local_cache_should_read_and_write_false
assert_equal false, @cache.read(key)
end
end

def test_local_cache_should_deserialize_entries_on_multi_get
keys = Array.new(5) { SecureRandom.uuid }
values = keys.index_with(true)
@cache.with_local_cache do
assert @cache.write_multi(values)
assert_equal values, @cache.read_multi(*keys)
end
end
end

0 comments on commit 3933a41

Please sign in to comment.