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

Breadcrumb

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

function DatabaseBackend::garbageCollection

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/Flood/DatabaseBackend.php \Drupal\Core\Flood\DatabaseBackend::garbageCollection()

Overrides CacheBackendInterface::garbageCollection

File

core/lib/Drupal/Core/Cache/DatabaseBackend.php, line 391

Class

DatabaseBackend
Defines a default cache implementation.

Namespace

Drupal\Core\Cache

Code

public function garbageCollection() {
    try {
        // Bounded size cache bin, using FIFO.
        if ($this->maxRows !== static::MAXIMUM_NONE) {
            $first_invalid_create_time = $this->connection
                ->select($this->bin)
                ->fields($this->bin, [
                'created',
            ])
                ->orderBy("{$this->bin}.created", 'DESC')
                ->range($this->maxRows, 1)
                ->execute()
                ->fetchField();
            if ($first_invalid_create_time) {
                $this->connection
                    ->delete($this->bin)
                    ->condition('created', $first_invalid_create_time, '<=')
                    ->execute();
            }
        }
        $this->connection
            ->delete($this->bin)
            ->condition('expire', Cache::PERMANENT, '<>')
            ->condition('expire', $this->time
            ->getRequestTime(), '<')
            ->execute();
    } catch (\Exception) {
        // If the table does not exist, it surely does not have garbage in it.
        // If the table exists, the next garbage collection will clean up.
        // There is nothing to do.
    }
}

API Navigation

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