From 6a1ee787a0bbf6bae2ca942cc90482d735bd1e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 14 Oct 2021 17:45:44 +0000 Subject: [PATCH] Disable Dalli compression on the protocal level We were disabling in the write level but since Dalli 3 the protocol is compressing by default and ignoring the option at write level. --- .../lib/active_support/cache/mem_cache_store.rb | 9 ++++++--- activesupport/test/cache/cache_store_setting_test.rb | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index de0fc8abb8..d5d7ad6bc6 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -121,7 +121,9 @@ module ActiveSupport @data = addresses.first else mem_cache_options = options.dup - UNIVERSAL_OPTIONS.each { |name| mem_cache_options.delete(name) } + # The value "compress: false" prevents duplicate compression within Dalli. + mem_cache_options[:compress] = false + (UNIVERSAL_OPTIONS - %i(compress)).each { |name| mem_cache_options.delete(name) } @data = self.class.build_mem_cache(*(addresses + [mem_cache_options])) end end @@ -236,8 +238,9 @@ module ActiveSupport expires_in += 5.minutes end rescue_error_with false do - # The value "compress: false" prevents duplicate compression within Dalli. - @data.with { |c| c.send(method, key, payload, expires_in, **options, compress: false) } + # Don't pass compress option to Dalli since we are already dealing with compression. + options.delete(:compress) + @data.with { |c| c.send(method, key, payload, expires_in, **options) } end end diff --git a/activesupport/test/cache/cache_store_setting_test.rb b/activesupport/test/cache/cache_store_setting_test.rb index 4ed1f1f1f1..b9fdc5bf2e 100644 --- a/activesupport/test/cache/cache_store_setting_test.rb +++ b/activesupport/test/cache/cache_store_setting_test.rb @@ -28,7 +28,7 @@ class CacheStoreSettingTest < ActiveSupport::TestCase end def test_mem_cache_fragment_cache_store - assert_called_with(Dalli::Client, :new, [%w[localhost], {}]) do + assert_called_with(Dalli::Client, :new, [%w[localhost], { compress: false }]) do store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost" assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end @@ -52,14 +52,14 @@ class CacheStoreSettingTest < ActiveSupport::TestCase end def test_mem_cache_fragment_cache_store_with_multiple_servers - assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], {}]) do + assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { compress: false }]) do store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1" assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end end def test_mem_cache_fragment_cache_store_with_options - assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10 }]) do + assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10, compress: false }]) do store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1", namespace: "foo", timeout: 10 assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) assert_equal "foo", store.options[:namespace]