Class: Dalli::Protocol::Meta::KeyRegularizer
- Inherits:
-
Object
- Object
- Dalli::Protocol::Meta::KeyRegularizer
- Defined in:
- lib/dalli/protocol/meta/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.
Constant Summary collapse
- WHITESPACE =
/\s/.freeze
Class Method Summary collapse
Class Method Details
.decode(encoded_key, base64_encoded) ⇒ Object
23 24 25 26 27 |
# File 'lib/dalli/protocol/meta/key_regularizer.rb', line 23 def self.decode(encoded_key, base64_encoded) return encoded_key unless base64_encoded Base64.strict_decode64(encoded_key).force_encoding(Encoding::UTF_8) end |
.encode(key) ⇒ Object
17 18 19 20 21 |
# File 'lib/dalli/protocol/meta/key_regularizer.rb', line 17 def self.encode(key) return [key, false] if key.ascii_only? && !WHITESPACE.match(key) [Base64.strict_encode64(key), true] end |