function FileCache::set

8.0.x FileCache.php FileCache::set($cid, $data, $expire = DRUSH_CACHE_PERMANENT)
7.x FileCache.php FileCache::set($cid, $data, $expire = DRUSH_CACHE_PERMANENT)
master FileCache.php FileCache::set($cid, $data, $expire = DRUSH_CACHE_PERMANENT)

Store data in the persistent cache.


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

array $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 CacheInterface::set


lib/Drush/Cache/FileCache.php, line 73
Definition of Drush\Cache\FileCache.




Default cache implementation.


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

  $cache = new \stdClass;
  $cache->cid = $cid;
  $cache->data = is_object($data) ? clone $data : $data;
  $cache->created = $created;
  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.

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