X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FCache%2FDatabaseBackendFactory.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FCache%2FDatabaseBackendFactory.php;h=b86390e19656182af8fe9d1eb998c755969ed181;hp=8aa018ec45333615a60681f77cb51541157be2fe;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php b/web/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php index 8aa018ec4..b86390e19 100644 --- a/web/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php +++ b/web/core/lib/Drupal/Core/Cache/DatabaseBackendFactory.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Cache; use Drupal\Core\Database\Connection; +use Drupal\Core\Site\Settings; class DatabaseBackendFactory implements CacheFactoryInterface { @@ -20,6 +21,13 @@ class DatabaseBackendFactory implements CacheFactoryInterface { */ protected $checksumProvider; + /** + * The settings array. + * + * @var \Drupal\Core\Site\Settings + */ + protected $settings; + /** * Constructs the DatabaseBackendFactory object. * @@ -27,10 +35,15 @@ class DatabaseBackendFactory implements CacheFactoryInterface { * Database connection * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. + * @param \Drupal\Core\Site\Settings $settings + * (optional) The settings array. + * + * @throws \BadMethodCallException */ - public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider) { + public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, Settings $settings = NULL) { $this->connection = $connection; $this->checksumProvider = $checksum_provider; + $this->settings = $settings ?: Settings::getInstance(); } /** @@ -43,7 +56,35 @@ class DatabaseBackendFactory implements CacheFactoryInterface { * The cache backend object for the specified cache bin. */ public function get($bin) { - return new DatabaseBackend($this->connection, $this->checksumProvider, $bin); + $max_rows = $this->getMaxRowsForBin($bin); + return new DatabaseBackend($this->connection, $this->checksumProvider, $bin, $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]; + } + // Second, use configured default backend. + 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; } }