Module: ActiveSupport::Cache::SerializerWithFallback::Marshal70WithFallback

Extended by:
Marshal70WithFallback
Includes:
ActiveSupport::Cache::SerializerWithFallback
Included in:
Marshal70WithFallback
Defined in:
activesupport/lib/active_support/cache/serializer_with_fallback.rb

Constant Summary collapse

MARK_UNCOMPRESSED =
"\x00".b.freeze
MARK_COMPRESSED =
"\x01".b.freeze

Instance Method Summary collapse

Methods included from ActiveSupport::Cache::SerializerWithFallback

[], #load

Instance Method Details

#_load(marked) ⇒ Object



110
111
112
113
114
# File 'activesupport/lib/active_support/cache/serializer_with_fallback.rb', line 110

def _load(marked)
  dumped = marked.byteslice(1..-1)
  dumped = Zlib::Inflate.inflate(dumped) if marked.start_with?(MARK_COMPRESSED)
  Cache::Entry.unpack(marshal_load(dumped))
end

#dump(entry) ⇒ Object



95
96
97
# File 'activesupport/lib/active_support/cache/serializer_with_fallback.rb', line 95

def dump(entry)
  MARK_UNCOMPRESSED + Marshal.dump(entry.pack)
end

#dump_compressed(entry, threshold) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'activesupport/lib/active_support/cache/serializer_with_fallback.rb', line 99

def dump_compressed(entry, threshold)
  dumped = Marshal.dump(entry.pack)

  if dumped.bytesize >= threshold
    compressed = Zlib::Deflate.deflate(dumped)
    return MARK_COMPRESSED + compressed if compressed.bytesize < dumped.bytesize
  end

  MARK_UNCOMPRESSED + dumped
end

#dumped?(dumped) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'activesupport/lib/active_support/cache/serializer_with_fallback.rb', line 116

def dumped?(dumped)
  dumped.start_with?(MARK_UNCOMPRESSED, MARK_COMPRESSED)
end