Skip to content

Commit

Permalink
Merge pull request rails#44983 from shiro16/dalli-store-optimised-cac…
Browse files Browse the repository at this point in the history
…he-read_multi

Fixed: MemCacheStore#read_multi_entries NoMethodError: undefined method `expired?` for nil:NilClass
  • Loading branch information
byroot committed May 3, 2022
2 parents c30ef14 + 0beacc3 commit 1b884cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache/mem_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def read_multi_entries(names, **options)
raw_values.each do |key, value|
entry = deserialize_entry(value, raw: options[:raw])

unless entry.expired? || entry.mismatched?(normalize_version(keys_to_names[key], options))
unless entry.nil? || entry.expired? || entry.mismatched?(normalize_version(keys_to_names[key], options))
values[keys_to_names[key]] = entry.value
end
end
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/cache/stores/mem_cache_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ def test_can_load_raw_falsey_values_from_dalli_store_with_local_cache
end
end

def test_can_read_multi_entries_raw_values_from_dalli_store
key = "test-with-nil-value-the-way-the-dalli-store-did"

@cache.instance_variable_get(:@data).with { |c| c.set(@cache.send(:normalize_key, key, nil), nil, 0, compress: false) }
assert_equal({}, @cache.send(:read_multi_entries, [key]))
end

private
def random_string(length)
(0...length).map { (65 + rand(26)).chr }.join
Expand Down

0 comments on commit 1b884cf

Please sign in to comment.