diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index d783b92819183..bb04a94cbe91a 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -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 diff --git a/activesupport/test/cache/stores/mem_cache_store_test.rb b/activesupport/test/cache/stores/mem_cache_store_test.rb index c8967f94bd425..2710d58c247d1 100644 --- a/activesupport/test/cache/stores/mem_cache_store_test.rb +++ b/activesupport/test/cache/stores/mem_cache_store_test.rb @@ -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