@@ -70,14 +70,6 @@ class RedisCacheStore < Store
70
70
# Support raw values in the local cache strategy.
71
71
module LocalCacheWithRaw # :nodoc:
72
72
private
73
- def read_entry ( key , options )
74
- entry = super
75
- if options [ :raw ] && local_cache && entry
76
- entry = deserialize_entry ( entry . value )
77
- end
78
- entry
79
- end
80
-
81
73
def write_entry ( key , entry , options )
82
74
if options [ :raw ] && local_cache
83
75
raw_entry = Entry . new ( serialize_entry ( entry , raw : true ) )
@@ -328,7 +320,8 @@ def set_redis_capabilities
328
320
# Read an entry from the cache.
329
321
def read_entry ( key , options = nil )
330
322
failsafe :read_entry do
331
- deserialize_entry redis . with { |c | c . get ( key ) }
323
+ raw = options &.fetch ( :raw , false )
324
+ deserialize_entry ( redis . with { |c | c . get ( key ) } , raw : raw )
332
325
end
333
326
end
334
327
@@ -343,6 +336,7 @@ def read_multi_entries(names, _options)
343
336
def read_multi_mget ( *names )
344
337
options = names . extract_options!
345
338
options = merged_options ( options )
339
+ raw = options &.fetch ( :raw , false )
346
340
347
341
keys = names . map { |name | normalize_key ( name , options ) }
348
342
@@ -352,7 +346,7 @@ def read_multi_mget(*names)
352
346
353
347
names . zip ( values ) . each_with_object ( { } ) do |( name , value ) , results |
354
348
if value
355
- entry = deserialize_entry ( value )
349
+ entry = deserialize_entry ( value , raw : raw )
356
350
unless entry . nil? || entry . expired? || entry . mismatched? ( normalize_version ( name , options ) )
357
351
results [ name ] = entry . value
358
352
end
@@ -421,9 +415,20 @@ def truncate_key(key)
421
415
end
422
416
end
423
417
424
- def deserialize_entry ( serialized_entry )
418
+ def deserialize_entry ( serialized_entry , raw : )
425
419
if serialized_entry
426
420
entry = Marshal . load ( serialized_entry ) rescue serialized_entry
421
+
422
+ written_raw = serialized_entry . equal? ( entry )
423
+ if raw != written_raw
424
+ ActiveSupport ::Deprecation . warn ( <<-MSG . squish )
425
+ Using a different value for the raw option when reading and writing
426
+ to a cache key is deprecated for :redis_cache_store and Rails 6.0
427
+ will stop automatically detecting the format when reading to avoid
428
+ marshal loading untrusted raw strings.
429
+ MSG
430
+ end
431
+
427
432
entry . is_a? ( Entry ) ? entry : Entry . new ( entry )
428
433
end
429
434
end
0 commit comments