function CacheCollector::normalizeLockName

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheCollector.php \Drupal\Core\Cache\CacheCollector::normalizeLockName()
  2. 8.9.x core/lib/Drupal/Core/Cache/CacheCollector.php \Drupal\Core\Cache\CacheCollector::normalizeLockName()

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 CacheCollector::normalizeLockName()
CacheCollectorHelper::normalizeLockName in core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php
Normalizes a cache ID in order to comply with database limitations.
1 method overrides CacheCollector::normalizeLockName()
CacheCollectorHelper::normalizeLockName in core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php
Normalizes a cache ID in order to comply with database limitations.

File

core/lib/Drupal/Core/Cache/CacheCollector.php, line 295

Class

CacheCollector
Default implementation for CacheCollectorInterface.

Namespace

Drupal\Core\Cache

Code

protected function normalizeLockName($cid) {
    @trigger_error(sprintf('%s is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. The lock service is responsible for normalizing the lock name. See https://www.drupal.org/node/3436961', __METHOD__), E_USER_DEPRECATED);
    // Nothing to do if the ID is a US ASCII string of 255 characters or less.
    $cid_is_ascii = mb_check_encoding($cid, 'ASCII');
    if (strlen($cid) <= 255 && $cid_is_ascii) {
        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.