Class: Dalli::Protocol::StringMarshaller

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/protocol/string_marshaller.rb

Overview

Dalli::Protocol::StringMarshaller is a pass-through marshaller for use with the :raw client option. It bypasses serialization and compression entirely, expecting values to already be strings (e.g., pre-serialized by Rails’ ActiveSupport::Cache). It still enforces the maximum value size limit.

Constant Summary collapse

DEFAULTS =
{
  # max size of value in bytes (default is 1 MB, can be overriden with "memcached -I <size>")
  value_max_bytes: 1024 * 1024
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_options) ⇒ StringMarshaller



19
20
21
22
23
# File 'lib/dalli/protocol/string_marshaller.rb', line 19

def initialize(client_options)
  @value_max_bytes = client_options.fetch(:value_max_bytes) do
    DEFAULTS.fetch(:value_max_bytes)
  end.to_i
end

Instance Attribute Details

#value_max_bytesObject (readonly)

Returns the value of attribute value_max_bytes.



17
18
19
# File 'lib/dalli/protocol/string_marshaller.rb', line 17

def value_max_bytes
  @value_max_bytes
end

Instance Method Details

#compress_by_default?Boolean



51
52
53
# File 'lib/dalli/protocol/string_marshaller.rb', line 51

def compress_by_default?
  false
end

#compression_min_sizeObject



47
48
49
# File 'lib/dalli/protocol/string_marshaller.rb', line 47

def compression_min_size
  nil
end

#compressorObject



43
44
45
# File 'lib/dalli/protocol/string_marshaller.rb', line 43

def compressor
  nil
end

#retrieve(value, _flags) ⇒ Object



32
33
34
# File 'lib/dalli/protocol/string_marshaller.rb', line 32

def retrieve(value, _flags)
  value
end

#serializerObject

Interface compatibility methods - these return nil since StringMarshaller bypasses serialization and compression entirely.



39
40
41
# File 'lib/dalli/protocol/string_marshaller.rb', line 39

def serializer
  nil
end

#store(key, value, _options = nil) ⇒ Object

Raises:



25
26
27
28
29
30
# File 'lib/dalli/protocol/string_marshaller.rb', line 25

def store(key, value, _options = nil)
  raise MarshalError, "Dalli in :raw mode only supports strings, got: #{value.class}" unless value.is_a?(String)

  error_if_over_max_value_bytes(key, value)
  [value, 0]
end