function DatabaseBackend::normalizeCid
Normalizes a cache ID in order to comply with database limitations.
Parameters
string $cid: The passed in cache ID.
Return value
string An ASCII-encoded cache ID that is at most 255 characters long.
1 call to DatabaseBackend::normalizeCid()
- DatabaseBackend::doSetMultiple in core/lib/ Drupal/ Core/ Cache/ DatabaseBackend.php 
- Stores multiple items in the persistent cache.
File
- 
              core/lib/ Drupal/ Core/ Cache/ DatabaseBackend.php, line 499 
Class
- DatabaseBackend
- Defines a default cache implementation.
Namespace
Drupal\Core\CacheCode
protected function normalizeCid($cid) {
  // Nothing to do if the ID is a US ASCII string of 255 characters or less.
  // Additionally check for trailing spaces in the cache ID because MySQL
  // may or may not take these into account when making comparisons.
  // @see https://dev.mysql.com/doc/refman/9.0/en/char.html
  $cid_is_ascii = mb_check_encoding($cid, 'ASCII');
  if (strlen($cid) <= 255 && $cid_is_ascii && !str_ends_with($cid, ' ')) {
    return $cid;
  }
  // Return a string that uses as much as possible of the original cache ID
  // with the hash appended.
  $hash = Crypt::hashBase64($cid);
  if (!$cid_is_ascii) {
    return $hash;
  }
  return substr($cid, 0, 255 - strlen($hash)) . $hash;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
