instance method normalize_key

Ruby on Rails 8.0.4

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

normalize_key(key, options)

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.

Parameters

key req
options req
Source
# File activesupport/lib/active_support/cache/mem_cache_store.rb, line 251
        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

Defined in activesupport/lib/active_support/cache/mem_cache_store.rb line 251 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Cache::MemCacheStore

Type at least 2 characters to search.

↑↓ navigate · open · esc close