Method: ActiveSupport::Cache::Coder#dump_compressed

Defined in:
lib/active_support/cache/coder.rb

#dump_compressed(entry, threshold) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_support/cache/coder.rb', line 20

def dump_compressed(entry, threshold)
  return @serializer.dump_compressed(entry, threshold) if @legacy_serializer

  # If value is a string with a supported encoding, use it as the payload
  # instead of passing it through the serializer.
  if type = type_for_string(entry.value)
    payload = entry.value.b
  else
    type = OBJECT_DUMP_TYPE
    payload = @serializer.dump(entry.value)
  end

  if compressed = try_compress(payload, threshold)
    payload = compressed
    type = type | COMPRESSED_FLAG
  end

  expires_at = entry.expires_at || -1.0

  version = dump_version(entry.version) if entry.version
  version_length = version&.bytesize || -1

  packed = SIGNATURE.b
  packed << [type, expires_at, version_length].pack(PACKED_TEMPLATE)
  packed << version if version
  packed << payload
end