Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Cache.php

function Cache::gc

Return value

bool

File

vendor/composer/composer/src/Composer/Cache.php, line 303

Class

Cache
Reads/writes to a filesystem cache

Namespace

Composer

Code

public function gc(int $ttl, int $maxSize) {
    if ($this->isEnabled() && !$this->readOnly) {
        $expire = new \DateTime();
        $expire->modify('-' . $ttl . ' seconds');
        $finder = $this->getFinder()
            ->date('until ' . $expire->format('Y-m-d H:i:s'));
        foreach ($finder as $file) {
            $this->filesystem
                ->unlink($file->getPathname());
        }
        $totalSize = $this->filesystem
            ->size($this->root);
        if ($totalSize > $maxSize) {
            $iterator = $this->getFinder()
                ->sortByAccessedTime()
                ->getIterator();
            while ($totalSize > $maxSize && $iterator->valid()) {
                $filepath = $iterator->current()
                    ->getPathname();
                $totalSize -= $this->filesystem
                    ->size($filepath);
                $this->filesystem
                    ->unlink($filepath);
                $iterator->next();
            }
        }
        self::$cacheCollected = true;
        return true;
    }
    return false;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal