You are here

function DrupalFileCache::encode_cid in File Cache 7

Make cache ID usable for file name.

Parameters

$cid: Cache ID.

Return value

String that is derived from $cid and can be used as file name.

4 calls to DrupalFileCache::encode_cid()
DrupalFileCache::all in ./filecache.inc
List of all cache objects with specified prefix in their name.
DrupalFileCache::delete_one in ./filecache.inc
Delete a single cache object.
DrupalFileCache::get in ./filecache.inc
Return data from the persistent cache. Data may be stored as either plain text or as serialized data. cache_get will automatically return unserialized objects and arrays.
DrupalFileCache::set in ./filecache.inc
Store data in the persistent cache.

File

./filecache.inc, line 193
DrupalFileCache class that implements DrupalCacheInterface.

Class

DrupalFileCache

Code

function encode_cid($cid) {

  // Use urlencode(), but turn the
  // encoded ':' and '/' back into ordinary characters since they're used so
  // often. (Especially ':', but '/' is used in cache_menu.)
  // We can't turn them back into their own characters though; both are
  // considered unsafe in filenames. So turn ':' -> '@' and '/' -> '='
  $safe_cid = str_replace(array(
    '%3A',
    '%2F',
  ), array(
    '@',
    '=',
  ), urlencode($cid));
  if (strlen($safe_cid) > FILECACHE_CID_FILENAME_MAX) {
    $safe_cid = substr($safe_cid, 0, FILECACHE_CID_FILENAME_POS_BEFORE_MD5) . ',' . md5(substr($safe_cid, FILECACHE_CID_FILENAME_POS_BEFORE_MD5));
  }
  return $safe_cid;
}