mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
prevents raw redis and memcached compression
- Fixes issue where reads with raw: true using redis or memcached cache store, will compress values on reads. - Should speed up raw cache reads by preventing unnecessary cpu intensive operation.
This commit is contained in:
parent
8a4192fa3d
commit
f1fb097a74
5 changed files with 26 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
* Prevent `RedisCacheStore` and `MemCacheStore` from performing compression
|
||||
when reading entries written with `raw: true`.
|
||||
|
||||
*Max Gurewitz*
|
||||
|
||||
* `URI.parser` is deprecated and will be removed in Rails 6.2. Use
|
||||
`URI::DEFAULT_PARSER` instead.
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ module ActiveSupport
|
|||
|
||||
def deserialize_entry(entry)
|
||||
if entry
|
||||
entry.is_a?(Entry) ? entry : Entry.new(entry)
|
||||
entry.is_a?(Entry) ? entry : Entry.new(entry, compress: false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -454,7 +454,7 @@ module ActiveSupport
|
|||
def deserialize_entry(serialized_entry, raw:)
|
||||
if serialized_entry
|
||||
if raw
|
||||
Entry.new(serialized_entry)
|
||||
Entry.new(serialized_entry, compress: false)
|
||||
else
|
||||
Marshal.load(serialized_entry)
|
||||
end
|
||||
|
|
|
@ -76,6 +76,15 @@ class MemCacheStoreTest < ActiveSupport::TestCase
|
|||
assert_equal "2", cache.read("foo")
|
||||
end
|
||||
|
||||
def test_raw_read_entry_compression
|
||||
cache = lookup_store(raw: true)
|
||||
cache.write("foo", 2)
|
||||
|
||||
assert_not_called_on_instance_of ActiveSupport::Cache::Entry, :compress! do
|
||||
cache.read("foo")
|
||||
end
|
||||
end
|
||||
|
||||
def test_raw_values_with_marshal
|
||||
cache = lookup_store(raw: true)
|
||||
cache.write("foo", Marshal.dump([]))
|
||||
|
|
|
@ -304,4 +304,14 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
|||
assert_not cache.exist?("fu")
|
||||
end
|
||||
end
|
||||
|
||||
class RawTest < StoreTest
|
||||
test "does not compress values read with \"raw\" enabled" do
|
||||
@cache.write("foo", "bar", raw: true)
|
||||
|
||||
assert_not_called_on_instance_of ActiveSupport::Cache::Entry, :compress! do
|
||||
@cache.read("foo", raw: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue