class Dalli::Protocol::ValueMarshaller

Dalli::Protocol::ValueMarshaller compartmentalizes the logic for marshalling and unmarshalling unstructured data (values) to Memcached. It also enforces limits on the maximum size of marshalled data.

Constants

DEFAULTS
OPTIONS

Public Class Methods

new(client_options) click to toggle source
# File lib/dalli/protocol/value_marshaller.rb, line 24
def initialize(client_options)
  @value_serializer = ValueSerializer.new(client_options)
  @value_compressor = ValueCompressor.new(client_options)

  @marshal_options =
    DEFAULTS.merge(client_options.select { |k, _| OPTIONS.include?(k) })
end

Public Instance Methods

error_if_over_max_value_bytes(key, value) click to toggle source
# File lib/dalli/protocol/value_marshaller.rb, line 50
def error_if_over_max_value_bytes(key, value)
  return if value.bytesize <= value_max_bytes

  message = "Value for #{key} over max size: #{value_max_bytes} <= #{value.bytesize}"
  raise Dalli::ValueOverMaxSize, message
end
retrieve(value, flags) click to toggle source
# File lib/dalli/protocol/value_marshaller.rb, line 41
def retrieve(value, flags)
  value = @value_compressor.retrieve(value, flags)
  @value_serializer.retrieve(value, flags)
end
store(key, value, options = nil) click to toggle source
# File lib/dalli/protocol/value_marshaller.rb, line 32
def store(key, value, options = nil)
  bitflags = 0
  value, bitflags = @value_serializer.store(value, options, bitflags)
  value, bitflags = @value_compressor.store(value, options, bitflags)

  error_if_over_max_value_bytes(key, value)
  [value, bitflags]
end
value_max_bytes() click to toggle source
# File lib/dalli/protocol/value_marshaller.rb, line 46
def value_max_bytes
  @marshal_options[:value_max_bytes]
end