Clear a cache

@return bool
196819
public function clearCache()
    {
        $result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);

        if ($result != true) {
            throw new Exceptions\Error("Error while clearing cache");
        }

        $this->updateCacheTimestamp();

        return $result;
    }
1137683
public function clear($cache = null)
    {
        if ($cache === null) {
            $cache = $this->cache_name;
        }
        $cache = self::encodeCache($cache);
        $url = "projects/{$this->project_id}/caches/$cache/clear";
        $params = array();
        $this->setJsonHeaders();
        return self::json_decode($this->apiCall(self::POST, $url, $params));
    }
264074
public function erase(){
    	if($this->exists())
		{
			$query = new Query(static::table());
			$query->delete()->where($this->getIdentifyCondition());
			if($query->execute())
                $this->clear();
            return $query->success();
		}
        return false;
    }
1256769
public function clearCache()
    {
        if ($this->Using === 'APCu') {
            return $this->Modified = apcu_clear_cache();
        }
        if ($this->Using === 'Memcached') {
            return ($this->WorkingData->flush() && ($this->Modified = true));
        }
        if ($this->Using === 'Redis') {
            return ($this->WorkingData->flushDb() && ($this->Modified = true));
        }
        if ($this->Using === 'PDO') {
            $PDO = $this->WorkingData->prepare(self::clearQuery);
            if ($PDO !== false && $PDO->execute()) {
                return ($PDO->rowCount() > 0 && $this->Modified = true);
            }
            return false;
        }
        if (is_array($this->WorkingData)) {
            $this->WorkingData = [];
            return $this->Modified = true;
        }
        return false;
    }
714484
public function clearCache()
    {
        $cachePath = $this->cachePath();

        if (!file_exists($cachePath)) {
            return;
        }

        $dir = new RecursiveDirectoryIterator($cachePath, RecursiveDirectoryIterator::SKIP_DOTS);
        $files = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);

        foreach($files as $file) {
            $path = $file->getRealPath();
            $file->isDir() ? rmdir($path) : unlink($path);
        }
        rmdir($cachePath);
    }
319052
public function useCache()
    {
        if (is_callable($this->get_cache_callback)
            && is_callable($this->set_cache_callback)
            && is_callable($this->delete_cache_callback)) {
            return true;
        }

        return false;
    }
806986
public function cache_clear() {
		$cache = WP_CLI::get_cache();

		if ( ! $cache->is_enabled() ) {
			WP_CLI::error( 'Cache directory does not exist.' );
		}

		$cache->clear();

		WP_CLI::success( 'Cache cleared.' );
	}
679666
public function clearAll()
    {
        $prefixes = Cache::configured();
        foreach ($prefixes as $prefix) {
            $this->clear($prefix);
        }
    }
867497
protected function clearCache()
    {
        $oldCacheDirName = "{$this->cacheDir}_old";
        $this->fs->rename($this->cacheDir, $oldCacheDirName);
        $this->fs->remove($oldCacheDirName);
    }
984211
public function clear()
    {
        $result = false;
        if (false !== $files = @scandir($this->cachedir)) {
            foreach ($files as $file) {
                $file = $this->cachedir.DIRECTORY_SEPARATOR.$file;
                if (false === is_dir($file)) {
                    if (false === @unlink($file)) {
                        $this->log('warning', sprintf('Enable to remove cache file `%s`.', $file));
                    } else {
                        $result = true;
                    }
                }
            }
        }

        if (true === $result) {
            $this->log('debug', sprintf('File system cache cleared in `%s`.', $this->cachedir));
        }

        return $result;
    }
973923
public function clearFile()
    {
        $cleared = false;

        if (isset($this->file_pointer)) {
            $cleared = $this->file_pointer->ftruncate(0);
        }

        return $cleared;
    }
705137
public function purge() {
        if ($this->isready) {
            // Only use delete multi if we have the correct extension installed and if the memcached
            // server is shared (flushing the cache is quicker otherwise).
            $candeletemulti = ($this->candeletemulti && $this->isshared);

            if ($this->clustered) {
                foreach ($this->setconnections as $connection) {
                    if ($candeletemulti) {
                        $keys = self::get_prefixed_keys($connection, $this->prefix);
                        $connection->deleteMulti($keys);
                    } else {
                        // Oh damn, this isn't multi-site safe.
                        $connection->flush();
                    }
                }
            } else if ($candeletemulti) {
                $keys = self::get_prefixed_keys($this->connection, $this->prefix);
                $this->connection->deleteMulti($keys);
            } else {
                // Oh damn, this isn't multi-site safe.
                $this->connection->flush();
            }
        }
        // It never fails. Ever.
        return true;
    }
733687
public function clear(): bool
    {
        //TODO: check the need to call
        clearstatcache();
        
        $dh = @opendir($this->cacheDir);
        if (false === $dh) {
            return false;
        }
        
        while (false !== ($entry = readdir($dh))) {
            $file = $this->cacheDir . '/' . $entry;
            if (is_file($file) && 0 !== strpos($entry, '.')) { //exclude .htaccess
                unlink($file);
            }
        }
        
        closedir($dh);
        
        return true;
    }
476226
public function clear()
    {
        $key = $this->key();
        $files = glob($this->path . "/_cache-" . $key . "*.cache");
        $this->setKey();
        $this->key(true);
        foreach ($files as $file) {
            unlink($file);
        }
        return $this;
    }
1056936
public function clear()
    {
        $keys = eaccelerator_list_keys();
        if (is_array($keys)) {
            foreach ($keys as $info) {
                // eaccelerator bug (Http://eaccelerator.net/ticket/287)
                if (0 === strpos($info['name'], ':')) {
                    $key = substr($info['name'], 1);
                } else {
                    $key = $info['name'];
                }

                if (!eaccelerator_rm($key)) {
                    return false;
                }
            }
        }

        return true;
    }
608255
public function clear($name = null)
    {
        $cache = $this->_getSchemaCache();
        $tables = $cache->clear($name);

        foreach ($tables as $table) {
            $this->verbose(sprintf('Cleared "%s"', $table));
        }

        $this->out('<success>Cache clear complete</success>');

        return true;
    }
1305714
public function clear()
    {
        foreach ($this->filesystem()->listContents() as $file) {
            $this->filesystem()->delete($file['path']);
        }

        return true;
    }