You are here

protected function DatabaseRawBackend::normalizeCid in Supercache 8

Same name and namespace in other branches
  1. 2.0.x src/Cache/DatabaseRawBackend.php \Drupal\supercache\Cache\DatabaseRawBackend::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.

2 calls to DatabaseRawBackend::normalizeCid()
DatabaseRawBackend::doCounter in src/Cache/DatabaseRawBackend.php
doCounter: if the $cid already exists and is not numeric should throw an exception. If it does not exist, should be populated with the default value.
DatabaseRawBackend::prepareStorage in src/Cache/DatabaseRawBackend.php
Prepare data to be stored in the database.

File

src/Cache/DatabaseRawBackend.php, line 513
Contains \Drupal\supercache\Cache\DatabaseRawBackend.

Class

DatabaseRawBackend
Defines a default cache implementation.

Namespace

Drupal\supercache\Cache

Code

protected function normalizeCid($cid) {

  // 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;
}