"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php" (26 Nov 2020, 2530 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DatabaseBackendFactory.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\Core\Cache;
    4 
    5 use Drupal\Core\Database\Connection;
    6 use Drupal\Core\Site\Settings;
    7 
    8 class DatabaseBackendFactory implements CacheFactoryInterface {
    9 
   10   /**
   11    * The database connection.
   12    *
   13    * @var \Drupal\Core\Database\Connection
   14    */
   15   protected $connection;
   16 
   17   /**
   18    * The cache tags checksum provider.
   19    *
   20    * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
   21    */
   22   protected $checksumProvider;
   23 
   24   /**
   25    * The site settings.
   26    *
   27    * @var \Drupal\Core\Site\Settings
   28    */
   29   protected $settings;
   30 
   31   /**
   32    * Constructs the DatabaseBackendFactory object.
   33    *
   34    * @param \Drupal\Core\Database\Connection $connection
   35    *   Database connection
   36    * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
   37    *   The cache tags checksum provider.
   38    * @param \Drupal\Core\Site\Settings $settings
   39    *   (optional) The site settings.
   40    *
   41    * @throws \BadMethodCallException
   42    */
   43   public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, Settings $settings = NULL) {
   44     $this->connection = $connection;
   45     $this->checksumProvider = $checksum_provider;
   46     $this->settings = $settings ?: Settings::getInstance();
   47   }
   48 
   49   /**
   50    * Gets DatabaseBackend for the specified cache bin.
   51    *
   52    * @param $bin
   53    *   The cache bin for which the object is created.
   54    *
   55    * @return \Drupal\Core\Cache\DatabaseBackend
   56    *   The cache backend object for the specified cache bin.
   57    */
   58   public function get($bin) {
   59     $max_rows = $this->getMaxRowsForBin($bin);
   60     return new DatabaseBackend($this->connection, $this->checksumProvider, $bin, $max_rows);
   61   }
   62 
   63   /**
   64    * Gets the max rows for the specified cache bin.
   65    *
   66    * @param string $bin
   67    *   The cache bin for which the object is created.
   68    *
   69    * @return int
   70    *   The maximum number of rows for the given bin. Defaults to
   71    *   DatabaseBackend::DEFAULT_MAX_ROWS.
   72    */
   73   protected function getMaxRowsForBin($bin) {
   74     $max_rows_settings = $this->settings->get('database_cache_max_rows');
   75     // First, look for a cache bin specific setting.
   76     if (isset($max_rows_settings['bins'][$bin])) {
   77       $max_rows = $max_rows_settings['bins'][$bin];
   78     }
   79     // Second, use configured default backend.
   80     elseif (isset($max_rows_settings['default'])) {
   81       $max_rows = $max_rows_settings['default'];
   82     }
   83     else {
   84       // Fall back to the default max rows if nothing else is configured.
   85       $max_rows = DatabaseBackend::DEFAULT_MAX_ROWS;
   86     }
   87     return $max_rows;
   88   }
   89 
   90 }