Memcache keys are binaries. So we need to force their encoding to binary
before applying the regular expression to ensure we are escaping all
characters properly.
# File activesupport/lib/active_support/cache/mem_cache_store.rb, line 311
def normalize_key(key, options)
key = super
if key
key = key.dup.force_encoding(Encoding::ASCII_8BIT)
key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
if key.size > KEY_MAX_SIZE
key_separator = ":hash:"
key_hash = ActiveSupport::Digest.hexdigest(key)
key_trim_size = KEY_MAX_SIZE - key_separator.size - key_hash.size
key = "#{key[0, key_trim_size]}#{key_separator}#{key_hash}"
end
end
key
end