Module: Dalli::Protocol::Meta::KeyRegularizer

Defined in:
lib/dalli/protocol/key_regularizer.rb

Overview

The meta protocol requires that keys be ASCII only, so Unicode keys are not supported. In addition, the use of whitespace in the key is not allowed. memcached supports the use of base64 hashes for keys containing whitespace or non-ASCII characters, provided the 'b' flag is included in the request.

Class Method Summary collapse

Class Method Details

.decode(encoded_key) ⇒ Object



23
24
25
26
# File 'lib/dalli/protocol/key_regularizer.rb', line 23

def decode(encoded_key)
  strict_base64_decoded = encoded_key.unpack1('m0')
  strict_base64_decoded.force_encoding(Encoding::UTF_8)
end

.encode(key) ⇒ Object



19
20
21
# File 'lib/dalli/protocol/key_regularizer.rb', line 19

def encode(key)
  [key].pack('m0')
end

.required?(key) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dalli/protocol/key_regularizer.rb', line 15

def required?(key)
  !key.ascii_only? || /\s/.match?(key)
end