function DrushFileCache::set

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

Store data in the persistent cache.


$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


includes/, line 350
Drush cache API


Default cache implementation.


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 + ;
  // Expire time is in seconds if less than 30 days, otherwise is a timestamp.
  elseif ($expire != DRUSH_CACHE_PERMANENT && $expire < ) {
    $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.

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