Skip to content

Commit

Permalink
Merge pull request #42559 from ghiculescu/patch-4
Browse files Browse the repository at this point in the history
MemCacheStore: always convert underlying values into an `Entry`
  • Loading branch information
byroot committed Jun 22, 2021
2 parents e3e3a97 + e60f3ff commit 0d54271
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -198,7 +198,7 @@ def normalize_key(key, options)

def deserialize_entry(payload)
entry = super
entry = Entry.new(entry, compress: false) if entry && !entry.is_a?(Entry)
entry = Entry.new(entry, compress: false) unless entry.nil? || entry.is_a?(Entry)
entry
end

Expand Down
32 changes: 32 additions & 0 deletions activesupport/test/cache/stores/mem_cache_store_test.rb
Expand Up @@ -211,6 +211,38 @@ def test_large_object_with_default_compression_settings
assert_compressed(LARGE_OBJECT)
end

def test_can_read_and_write_falsy_value
key = "test-with-false-value-through-public-api"

@cache.write(key, false)
assert_equal false, @cache.read(key)
end

def test_can_load_raw_values_from_dalli_store
key = "test-with-false-value-the-way-the-dalli-store-did"

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

def test_can_read_and_write_falsy_value_with_local_cache
key = "test-with-false-value-through-public-api"

@cache.write(key, false)
@cache.with_local_cache do
assert_equal false, @cache.read(key)
end
end

def test_can_load_raw_values_from_dalli_store_with_local_cache
key = "test-with-false-value-the-way-the-dalli-store-did"

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

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

0 comments on commit 0d54271

Please sign in to comment.