Nette\Caching\Storages\FileStorage::clean PHP Method

clean() public method

Removes items from the cache by conditions & garbage collector.
public clean ( array $conditions ) : void
$conditions array
return void
    public function clean(array $conditions)
    {
        $all = !empty($conditions[Cache::ALL]);
        $collector = empty($conditions);
        // cleaning using file iterator
        if ($all || $collector) {
            $now = time();
            foreach (Nette\Utils\Finder::find('_*')->from($this->dir)->childFirst() as $entry) {
                $path = (string) $entry;
                if ($entry->isDir()) {
                    // collector: remove empty dirs
                    @rmdir($path);
                    // @ - removing dirs is not necessary
                    continue;
                }
                if ($all) {
                    $this->delete($path);
                } else {
                    // collector
                    $meta = $this->readMetaAndLock($path, LOCK_SH);
                    if (!$meta) {
                        continue;
                    }
                    if (!empty($meta[self::META_DELTA]) && filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < $now || !empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < $now) {
                        $this->delete($path, $meta[self::HANDLE]);
                        continue;
                    }
                    flock($meta[self::HANDLE], LOCK_UN);
                    fclose($meta[self::HANDLE]);
                }
            }
            if ($this->journal) {
                $this->journal->clean($conditions);
            }
            return;
        }
        // cleaning using journal
        if ($this->journal) {
            foreach ($this->journal->clean($conditions) as $file) {
                $this->delete($file);
            }
        }
    }