class DatabaseBackendFactory

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php \Drupal\Core\Cache\DatabaseBackendFactory
  2. 8.9.x core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php \Drupal\Core\Cache\DatabaseBackendFactory
  3. 11.x core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php \Drupal\Core\Cache\DatabaseBackendFactory

Hierarchy

Expanded class hierarchy of DatabaseBackendFactory

2 files declare their use of DatabaseBackendFactory
DatabaseBackendFactoryTest.php in core/tests/Drupal/Tests/Core/Cache/DatabaseBackendFactoryTest.php
EndOfTransactionQueriesTest.php in core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
1 string reference to 'DatabaseBackendFactory'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses DatabaseBackendFactory
cache.backend.database in core/core.services.yml
Drupal\Core\Cache\DatabaseBackendFactory

File

core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php, line 10

Namespace

Drupal\Core\Cache
View source
class DatabaseBackendFactory implements CacheFactoryInterface {
    
    /**
     * The database connection.
     *
     * @var \Drupal\Core\Database\Connection
     */
    protected $connection;
    
    /**
     * The cache tags checksum provider.
     *
     * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
     */
    protected $checksumProvider;
    
    /**
     * Constructs the DatabaseBackendFactory object.
     *
     * @param \Drupal\Core\Database\Connection $connection
     *   Database connection
     * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
     *   The cache tags checksum provider.
     * @param \Drupal\Core\Site\Settings $settings
     *   (optional) The site settings.
     * @param \Drupal\Component\Serialization\ObjectAwareSerializationInterface|null $serializer
     *   (optional) The serializer to use.
     * @param \Drupal\Component\Datetime\TimeInterface|null $time
     *   The time service.
     *
     * @throws \BadMethodCallException
     */
    public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, ?Settings $settings = NULL, ?ObjectAwareSerializationInterface $serializer = NULL, ?TimeInterface $time = NULL) {
        $this->connection = $connection;
        $this->checksumProvider = $checksum_provider;
        if ($this->settings === NULL) {
            @trigger_error('Calling ' . __METHOD__ . ' without the $settings 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->settings = Settings::getInstance();
        }
        if ($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 === NULL) {
            @trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
            $this->time = \Drupal::service(TimeInterface::class);
        }
    }
    
    /**
     * Gets DatabaseBackend for the specified cache bin.
     *
     * @param $bin
     *   The cache bin for which the object is created.
     *
     * @return \Drupal\Core\Cache\DatabaseBackend
     *   The cache backend object for the specified cache bin.
     */
    public function get($bin) {
        $max_rows = $this->getMaxRowsForBin($bin);
        return new DatabaseBackend($this->connection, $this->checksumProvider, $bin, $this->serializer, $this->time, $max_rows);
    }
    
    /**
     * Gets the max rows for the specified cache bin.
     *
     * @param string $bin
     *   The cache bin for which the object is created.
     *
     * @return int
     *   The maximum number of rows for the given bin. Defaults to
     *   DatabaseBackend::DEFAULT_MAX_ROWS.
     */
    protected function getMaxRowsForBin($bin) {
        $max_rows_settings = $this->settings
            ->get('database_cache_max_rows');
        // First, look for a cache bin specific setting.
        if (isset($max_rows_settings['bins'][$bin])) {
            $max_rows = $max_rows_settings['bins'][$bin];
        }
        elseif (isset($max_rows_settings['default'])) {
            $max_rows = $max_rows_settings['default'];
        }
        else {
            // Fall back to the default max rows if nothing else is configured.
            $max_rows = DatabaseBackend::DEFAULT_MAX_ROWS;
        }
        return $max_rows;
    }

}

Members

Title Sort descending Modifiers Object type Summary
DatabaseBackendFactory::$checksumProvider protected property The cache tags checksum provider.
DatabaseBackendFactory::$connection protected property The database connection.
DatabaseBackendFactory::get public function Gets DatabaseBackend for the specified cache bin.
DatabaseBackendFactory::getMaxRowsForBin protected function Gets the max rows for the specified cache bin.
DatabaseBackendFactory::__construct public function Constructs the DatabaseBackendFactory object.

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