function DrushFileCache::set

6.x cache.inc DrushFileCache::set($cid, $data, $expire = DRUSH_CACHE_PERMANENT, array $headers = NULL)
5.x cache.inc DrushFileCache::set($cid, $data, $expire = DRUSH_CACHE_PERMANENT, array $headers = NULL)

Store data in the persistent cache.

Parameters

$cid: The cache ID of the data to store.

$data: The data to store in the cache.

$expire: One of the following values:

  • DRUSH_CACHE_PERMANENT: Indicates that the item should never be removed unless explicitly told to using _drush_cache_clear_all() with a cache ID.
  • DRUSH_CACHE_TEMPORARY: Indicates that the item should be removed at the next general cache wipe.
  • A Unix timestamp: Indicates that the item should be kept at least until the given time, after which it behaves like CACHE_TEMPORARY.

Overrides DrushCacheInterface::set

File

includes/cache.inc, line 349
Drush cache API

Class

DrushFileCache
Default cache implementation.

Code

function set($cid, $data, $expire = DRUSH_CACHE_PERMANENT, array $headers = NULL) {
  $created = time();

  $cache = new stdClass;
  $cache->cid = $cid;
  $cache->data = is_object($data) ? clone $data : $data;
  $cache->created = $created;
  $cache->headers = $headers;
  if ($expire == DRUSH_CACHE_TEMPORARY) {
    $cache->expire = $created + 2591999;
  }
  // Expire time is in seconds if less than 30 days, otherwise is a timestamp.
  elseif ($expire != DRUSH_CACHE_PERMANENT && $expire < 2592000) {
    $cache->expire = $created + $expire;
  }
  else {
    $cache->expire = $expire;
  }

  // Ensure the cache directory still exists, in case a backend process
  // cleared the cache after the cache was initialized.
  drush_mkdir($this->directory);

  $filename = $this->getFilePath($cid);
  return $this->writeFile($filename, $cache);
}