diff -u b/core/core.services.yml b/core/core.services.yml --- b/core/core.services.yml +++ b/core/core.services.yml @@ -79,6 +79,7 @@ class: Drupal\Core\Config\ConfigFactory tags: - { name: persist } + - { name: event_subscriber } arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] config.storage.staging: class: Drupal\Core\Config\FileStorage diff -u b/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php --- b/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -9,6 +9,7 @@ use Drupal\Core\Language\Language; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Defines the configuration object factory. @@ -23,7 +24,7 @@ * * @see \Drupal\Core\Config\StorageInterface */ -class ConfigFactory { +class ConfigFactory implements EventSubscriberInterface { /** * Prefix for all language configuration files. @@ -150,7 +151,7 @@ if (isset($module_overrides[$name])) { $this->cache[$cache_key]->setModuleOverride($module_overrides[$name]); } - // Apply any settigns.php overrides. + // Apply any settings.php overrides. if (isset($conf[$name])) { $this->cache[$cache_key]->setSettingsOverride($conf[$name]); } @@ -380,7 +381,7 @@ * It will be the same name with a prefix depending on language code: * language.config.LANGCODE.NAME * - * @param string $names + * @param array $names * A list of configuration object names. * * @return array @@ -437,2 +438,26 @@ + /** + * Removes stale static cache entries when configuration is saved. + * + * @param ConfigEvent $event + * The configuration event. + */ + public function onConfigSave(ConfigEvent $event) { + // Clear out any other cache keys apart from the config object being saved. + $saved_config = $event->getConfig(); + foreach ($this->getCacheKeys($saved_config->getName()) as $cache_key) { + if ($this->cache[$cache_key] != $saved_config) { + unset($this->cache[$cache_key]); + } + } + } + + /** + * {@inheritdoc} + */ + static function getSubscribedEvents() { + $events['config.save'][] = array('onConfigSave', 255); + return $events; + } + }