Skip to content

Commit 6a1ee78

Browse files
authored
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.
1 parent 370ef3d commit 6a1ee78

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

activesupport/lib/active_support/cache/mem_cache_store.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def initialize(*addresses)
121121
@data = addresses.first
122122
else
123123
mem_cache_options = options.dup
124-
UNIVERSAL_OPTIONS.each { |name| mem_cache_options.delete(name) }
124+
# The value "compress: false" prevents duplicate compression within Dalli.
125+
mem_cache_options[:compress] = false
126+
(UNIVERSAL_OPTIONS - %i(compress)).each { |name| mem_cache_options.delete(name) }
125127
@data = self.class.build_mem_cache(*(addresses + [mem_cache_options]))
126128
end
127129
end
@@ -236,8 +238,9 @@ def write_serialized_entry(key, payload, **options)
236238
expires_in += 5.minutes
237239
end
238240
rescue_error_with false do
239-
# The value "compress: false" prevents duplicate compression within Dalli.
240-
@data.with { |c| c.send(method, key, payload, expires_in, **options, compress: false) }
241+
# Don't pass compress option to Dalli since we are already dealing with compression.
242+
options.delete(:compress)
243+
@data.with { |c| c.send(method, key, payload, expires_in, **options) }
241244
end
242245
end
243246

activesupport/test/cache/cache_store_setting_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_file_store_requires_a_path
2828
end
2929

3030
def test_mem_cache_fragment_cache_store
31-
assert_called_with(Dalli::Client, :new, [%w[localhost], {}]) do
31+
assert_called_with(Dalli::Client, :new, [%w[localhost], { compress: false }]) do
3232
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
3333
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
3434
end
@@ -52,14 +52,14 @@ def test_mem_cache_fragment_cache_store_with_not_dalli_client
5252
end
5353

5454
def test_mem_cache_fragment_cache_store_with_multiple_servers
55-
assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], {}]) do
55+
assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { compress: false }]) do
5656
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1"
5757
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
5858
end
5959
end
6060

6161
def test_mem_cache_fragment_cache_store_with_options
62-
assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10 }]) do
62+
assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10, compress: false }]) do
6363
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1", namespace: "foo", timeout: 10
6464
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
6565
assert_equal "foo", store.options[:namespace]

0 commit comments

Comments
 (0)