Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemCacheStore: always convert underlying values into an Entry #42559

Merged
merged 1 commit into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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