You are here

public function DriverBase::key in Memcache API and Integration 8.2

Prepares the memcache key.

Parameters

string $key: The raw cache key.

Return value

string The prepared cache key.

Overrides DrupalMemcacheInterface::key

8 calls to DriverBase::key()
DriverBase::delete in src/Driver/DriverBase.php
Deletes an item from Memcache.
DriverBase::get in src/Driver/DriverBase.php
Retrieves a value from Memcache.
MemcachedDriver::add in src/Driver/MemcachedDriver.php
Add an item to Memcache if it doesn't exist already.
MemcachedDriver::getMulti in src/Driver/MemcachedDriver.php
Retrieves multiple values from Memcache.
MemcachedDriver::set in src/Driver/MemcachedDriver.php
Adds an item into memcache.

... See full list

File

src/Driver/DriverBase.php, line 101

Class

DriverBase
Class DriverBase.

Namespace

Drupal\memcache\Driver

Code

public function key($key) {
  $full_key = urlencode($this->prefix . '-' . $key);

  // Memcache only supports key lengths up to 250 bytes.  If we have generated
  // a longer key, we shrink it to an acceptable length with a configurable
  // hashing algorithm. Sha1 was selected as the default as it performs
  // quickly with minimal collisions.
  if (strlen($full_key) > 250) {
    $full_key = urlencode($this->prefix . '-' . hash($this->hashAlgorithm, $key));
    $full_key .= '-' . substr(urlencode($key), 0, 250 - 1 - strlen($full_key) - 1);
  }
  return $full_key;
}