diff --git a/core/lib/Drupal/Core/Cache/RuntimeCacheableDependencyInterface.php b/core/lib/Drupal/Core/Cache/MutableCacheableDependencyInterface.php similarity index 18% rename from core/lib/Drupal/Core/Cache/RuntimeCacheableDependencyInterface.php rename to core/lib/Drupal/Core/Cache/MutableCacheableDependencyInterface.php index 03d88d4..acfe5f6 100644 --- a/core/lib/Drupal/Core/Cache/RuntimeCacheableDependencyInterface.php +++ b/core/lib/Drupal/Core/Cache/MutableCacheableDependencyInterface.php @@ -1,41 +1,51 @@ cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts); + return $this; + } + + /** + * {@inheritdoc} + */ + public function addCacheTags(array $cache_tags) { + $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags); + return $this; + } + + /** + * {@inheritdoc} + */ + public function setCacheMaxAgeIfLower($max_age) { + $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age); + return $this; + } + +} diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index e88560e..51801b1 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -11,7 +11,8 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Cache\RuntimeCacheableDependencyInterface; +use Drupal\Core\Cache\MutableCacheableDependencyInterface; +use Drupal\Core\Cache\MutableCacheableDependencyTrait; use \Drupal\Core\DependencyInjection\DependencySerializationTrait; /** @@ -29,8 +30,9 @@ * @see \Drupal\Core\Config\Config * @see \Drupal\Core\Theme\ThemeSettings */ -abstract class ConfigBase implements CacheableDependencyInterface, RuntimeCacheableDependencyInterface { +abstract class ConfigBase implements CacheableDependencyInterface, MutableCacheableDependencyInterface { use DependencySerializationTrait; + use MutableCacheableDependencyTrait; /** * The name of the configuration object. @@ -47,27 +49,6 @@ protected $data = array(); /** - * The cache contexts this configuration object provides. - * - * @var string[] - */ - protected $cacheContexts = []; - - /** - * The cache tags this configuration object provides. - * - * @var string[] - */ - protected $cacheTags = []; - - /** - * The cache max age this configuration object provides. - * - * @var int - */ - protected $cacheMaxAge = Cache::PERMANENT; - - /** * The maximum length of a configuration object name. * * Many filesystems (including HFS, NTFS, and ext4) have a maximum file name @@ -308,25 +289,4 @@ public function getCacheMaxAge() { return $this->cacheMaxAge; } - /** - * {@inheritdoc} - */ - public function addRuntimeCacheContexts(array $cache_contexts) { - $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts); - } - - /** - * {@inheritdoc} - */ - public function addRuntimeCacheTags(array $cache_tags) { - $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags); - } - - /** - * {@inheritdoc} - */ - public function setRuntimeCacheMaxAge($max_age) { - $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age); - } - } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index b295297..907ea6d 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -9,8 +9,6 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\Context\CacheContextInterface; -use Drupal\Core\Cache\RuntimeCacheableDependencyInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -227,9 +225,9 @@ protected function loadOverrides(array $names) { */ protected function propagateCacheableDependencyOverrides($cache_key) { foreach ($this->configFactoryOverrides as $override) { - $this->cache[$cache_key]->addRuntimeCacheContexts($override->getCacheContexts()); - $this->cache[$cache_key]->addRuntimeCacheTags($override->getCacheTags()); - $this->cache[$cache_key]->setRuntimeCacheMaxAge($override->getCacheMaxAge()); + $this->cache[$cache_key]->addCacheContexts($override->getCacheContexts()); + $this->cache[$cache_key]->addCacheTags($override->getCacheTags()); + $this->cache[$cache_key]->setCacheMaxAgeIfLower($override->getCacheMaxAge()); } }