class ActiveSupport::Cache::MemCacheStore

def normalize_key(key, options)

characters properly.
before applying the regular expression to ensure we are escaping all
Memcache keys are binaries. So we need to force their encoding to binary
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