diff --git a/typo3/sysext/core/Classes/Cache/CacheManager.php b/typo3/sysext/core/Classes/Cache/CacheManager.php index 3fc34ef3bfaf442b94afbfe444d6ebe41c43d8d9..3ce75523a589750ad428d979ce69482d72d77a00 100644 --- a/typo3/sysext/core/Classes/Cache/CacheManager.php +++ b/typo3/sysext/core/Classes/Cache/CacheManager.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Cache; */ use TYPO3\CMS\Core\Cache\Backend\BackendInterface; +use TYPO3\CMS\Core\Cache\Backend\NullBackend; use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend; use TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException; use TYPO3\CMS\Core\Cache\Exception\InvalidBackendException; @@ -63,6 +64,19 @@ class CacheManager implements SingletonInterface 'groups' => ['all'] ]; + /** + * @var bool + */ + protected $disableCaching = false; + + /** + * @param bool $disableCaching + */ + public function __construct(bool $disableCaching = false) + { + $this->disableCaching = $disableCaching; + } + /** * Sets configurations for caches. The key of each entry specifies the * cache identifier and the value is an array of configuration options. @@ -285,6 +299,11 @@ class CacheManager implements SingletonInterface $backendOptions = $this->defaultCacheConfiguration['options']; } + if ($this->disableCaching) { + $backend = NullBackend::class; + $backendOptions = []; + } + // Add the cache identifier to the groups that it should be attached to, or use the default ones. if (isset($this->cacheConfigurations[$identifier]['groups']) && is_array($this->cacheConfigurations[$identifier]['groups'])) { $assignedGroups = $this->cacheConfigurations[$identifier]['groups']; diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php index 7acbee8a8c5f6345a2d8dd5a5d195f1bf3bbf5e2..0e8c570a5e43eb1504ee1c63ece9b975fe78ea84 100644 --- a/typo3/sysext/core/Classes/Core/Bootstrap.php +++ b/typo3/sysext/core/Classes/Core/Bootstrap.php @@ -279,11 +279,8 @@ class Bootstrap public function loadConfigurationAndInitialize($allowCaching = true, $packageManagerClassName = \TYPO3\CMS\Core\Package\PackageManager::class) { $this->populateLocalConfiguration() - ->initializeErrorHandling(); - if (!$allowCaching) { - $this->disableCoreCache(); - } - $this->initializeCachingFramework() + ->initializeErrorHandling() + ->initializeCachingFramework($allowCaching) ->initializePackageManagement($packageManagerClassName) ->initializeRuntimeActivatedPackagesFromConfiguration() ->setDefaultTimezone() @@ -367,6 +364,7 @@ class Bootstrap /** * Set cache_core to null backend, effectively disabling eg. the cache for ext_localconf and PackageManager etc. + * Used in unit tests. * * @return Bootstrap|null * @internal This is not a public API method, do not use in own extensions @@ -383,12 +381,13 @@ class Bootstrap * Initialize caching framework, and re-initializes it (e.g. in the install tool) by recreating the instances * again despite the Singleton instance * + * @param bool $allowCaching * @return Bootstrap * @internal This is not a public API method, do not use in own extensions */ - public function initializeCachingFramework() + public function initializeCachingFramework(bool $allowCaching = true) { - $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager(); + $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager(!$allowCaching); $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager); $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager); diff --git a/typo3/sysext/install/Classes/Http/Application.php b/typo3/sysext/install/Classes/Http/Application.php index a751aa3e86701daeb54239d7ea8c57b8988cb5d5..0b6181409580fc96fea956796637a53ce2118b5c 100644 --- a/typo3/sysext/install/Classes/Http/Application.php +++ b/typo3/sysext/install/Classes/Http/Application.php @@ -16,7 +16,6 @@ namespace TYPO3\CMS\Install\Http; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Cache\Backend\NullBackend; use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Http\AbstractApplication; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -63,8 +62,6 @@ class Application extends AbstractApplication $this->bootstrap ->startOutputBuffering() ->loadConfigurationAndInitialize(false, \TYPO3\CMS\Core\Package\FailsafePackageManager::class); - - $this->disableCachingFramework(); } /** @@ -83,26 +80,6 @@ class Application extends AbstractApplication throw new \TYPO3\CMS\Core\Exception('No suitable request handler found.', 1518448686); } - /** - * Set caching to NullBackend, install tool must not cache anything - */ - protected function disableCachingFramework() - { - $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']; - - $cacheConfigurationsWithCachesSetToNullBackend = []; - foreach ($cacheConfigurations as $cacheName => $cacheConfiguration) { - // cache_core is handled in bootstrap already - if (is_array($cacheConfiguration) && $cacheName !== 'cache_core') { - $cacheConfiguration['backend'] = NullBackend::class; - $cacheConfiguration['options'] = []; - } - $cacheConfigurationsWithCachesSetToNullBackend[$cacheName] = $cacheConfiguration; - } - $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); - $cacheManager->setCacheConfigurations($cacheConfigurationsWithCachesSetToNullBackend); - } - /** * Define constants */