You are here

public function FileSystemBackend::garbageCollection in File Cache 8

Performs garbage collection on a cache bin.

The backend may choose to delete expired or invalidated items.

Overrides CacheBackendInterface::garbageCollection

File

src/Cache/FileSystemBackend.php, line 239

Class

FileSystemBackend
A cache backend that stores cache items as files on the file system.

Namespace

Drupal\filecache\Cache

Code

public function garbageCollection() {
  $this
    ->ensureCacheFolderExists();
  $iterator = $this
    ->getFileSystemIterator();
  foreach ($iterator as $filename) {
    if (is_file($filename)) {
      if ($item = $this
        ->getFile($filename)) {
        $this
          ->prepareItem($item, TRUE);
        if (!$item->valid) {
          $this
            ->delete($item->cid);
        }
      }
    }
  }
}