You are here

protected static function MemcacheStorageAPI::preprocessCacheKey in Memcache Storage 7

Adds memcached key prefix and ensures that key is safe.

Parameters

$cache_id: Cache ID.

$cache_bin: Name of cache bin.

Return value

string Unique cache key.

6 calls to MemcacheStorageAPI::preprocessCacheKey()
MemcacheStorageAPI::add in ./memcache_storage.api.inc
Save data into memcached pool if key doesn't exist. Provide debug logging.
MemcacheStorageAPI::delete in ./memcache_storage.api.inc
Delete value from memcached pool. Provide debug logging.
MemcacheStorageAPI::deleteMultiple in ./memcache_storage.api.inc
Delete multiple cache items from memcached pool. Provide debug logging.
MemcacheStorageAPI::getMultiple in ./memcache_storage.api.inc
Get values from memcache storage. Provide debug logging.
MemcacheStorageAPI::replace in ./memcache_storage.api.inc
Replace existing data in memcache pool. Provide debug logging.

... See full list

File

./memcache_storage.api.inc, line 517
Provide class that processes memcached operations.

Class

MemcacheStorageAPI
Integrates with memcache API.

Code

protected static function preprocessCacheKey($cache_id, $cache_bin) {

  // Get key prefix from settings.php.
  $key_prefix = variable_get('memcache_storage_key_prefix', '');

  // Build unique cache key.
  $cache_key = $key_prefix ? $key_prefix . '-' : '';
  $cache_key .= $cache_bin ? $cache_bin . '-' : '';
  $cache_key .= $cache_id;

  // Add urlencode to avoid problems with different protocols.
  // If cache bin is 'cache_page' it means that we use external page cache.
  // Otherwise cache bin name is 'cache_page_[INDEX]'. We don't need to
  // encode url for external page cache because external servers may not be able
  // to urldecode this.
  $safe_key = $cache_bin == 'cache_page' ? $cache_key : urlencode($cache_key);

  // Memcache only supports key length up to 250 bytes. If we have generated
  // a longer key, hash it with md5 which will shrink the key down to 32 bytes
  // while still keeping it unique.
  if (strlen($safe_key) > 250) {
    $safe_key = md5($safe_key);
  }
  return $safe_key;
}