function DatabaseBackend::__construct

Same name in this branch
  1. 10 core/lib/Drupal/Core/Flood/DatabaseBackend.php \Drupal\Core\Flood\DatabaseBackend::__construct()
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Flood/DatabaseBackend.php \Drupal\Core\Flood\DatabaseBackend::__construct()
  2. 9 core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::__construct()
  3. 8.9.x core/lib/Drupal/Core/Flood/DatabaseBackend.php \Drupal\Core\Flood\DatabaseBackend::__construct()
  4. 8.9.x core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::__construct()
  5. 11.x core/lib/Drupal/Core/Flood/DatabaseBackend.php \Drupal\Core\Flood\DatabaseBackend::__construct()
  6. 11.x core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::__construct()

Constructs a DatabaseBackend object.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection.

\Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider: The cache tags checksum provider.

string $bin: The cache bin for which the object is created.

\Drupal\Component\Serialization\ObjectAwareSerializationInterface|int|string|null $serializer: (optional) The serializer to use.

\Drupal\Component\Datetime\TimeInterface|int|string|null $time: The time service.

int $max_rows: (optional) The maximum number of rows that are allowed in this cache bin table.

File

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

Class

DatabaseBackend
Defines a default cache implementation.

Namespace

Drupal\Core\Cache

Code

public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, $bin, ObjectAwareSerializationInterface|int|string|null $serializer = NULL, TimeInterface|int|string|null $time = NULL, $max_rows = NULL) {
    // All cache tables should be prefixed with 'cache_'.
    $bin = 'cache_' . $bin;
    $this->bin = $bin;
    $this->connection = $connection;
    $this->checksumProvider = $checksum_provider;
    if (is_int($this->serializer) || is_string($this->serializer)) {
        @trigger_error('Calling ' . __METHOD__ . ' with the $max_rows as 3rd argument is deprecated in drupal:10.3.0 and it will be the 4th argument in drupal:11.0.0. See https://www.drupal.org/node/3014684', E_USER_DEPRECATED);
        $max_rows = $this->serializer;
        $this->serializer = \Drupal::service('serialization.phpserialize');
    }
    elseif ($this->serializer === NULL) {
        @trigger_error('Calling ' . __METHOD__ . ' without the $serializer argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3014684', E_USER_DEPRECATED);
        $this->serializer = \Drupal::service('serialization.phpserialize');
    }
    if (!$this->time instanceof TimeInterface) {
        @trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 5th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
        if (is_int($time) || is_string($time)) {
            $max_rows = $time;
        }
        $this->time = \Drupal::service(TimeInterface::class);
    }
    $this->maxRows = $max_rows ?? static::DEFAULT_MAX_ROWS;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.