function FileCache::clear

8.0.x FileCache.php FileCache::clear($cid = NULL, $wildcard = FALSE)
7.x FileCache.php FileCache::clear($cid = NULL, $wildcard = FALSE)
master FileCache.php FileCache::clear($cid = NULL, $wildcard = FALSE)

Expire data from the cache. If called without arguments, expirable entries will be cleared from all known cache bins.

Parameters

string $cid: If set, the cache ID to delete. Otherwise, all cache entries that can expire are deleted.

bool $wildcard: If set to TRUE, the $cid is treated as a substring to match rather than a complete ID. The match is a right hand match. If '*' is given as $cid, the bin $bin will be emptied.

Overrides CacheInterface::clear

File

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

Namespace

Drush\Cache

Class

FileCache
Default cache implementation.

Code

function clear($cid = NULL, $wildcard = FALSE) {
  $bin_dir = $this->cacheDirectory();
  $files = array();
  if (empty($cid)) {
    drush_delete_dir($bin_dir, TRUE);
  }
  else {
    if ($wildcard) {
      if ($cid == '*') {
        drush_delete_dir($bin_dir, TRUE);
      }
      else {
        $matches = drush_scan_directory($bin_dir, "/^$cid/", array('.', '..'));
        $files = $files + array_keys($matches);
      }
    }
    else {
      $files[] = $this->getFilePath($cid);
    }

    foreach ($files as $f) {
      if (file_exists($f)) {
        unlink($f);
      }
    }
  }
}