‪TYPO3CMS  ‪main
ClearCacheService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
27 {
28  public function ‪__construct(
29  private readonly ‪LateBootService $lateBootService,
30  private readonly ‪FrontendInterface $dependencyInjectionCache
31  ) {}
32 
46  public function ‪clearAll(): void
47  {
48  // Flush all caches defined in TYPO3_CONF_VARS, but not the ones defined by extensions in ext_localconf.php
49  $baseCaches = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
50  $this->‪flushCaches($baseCaches);
51 
52  // Remove DI container cache (this might be removed in preference of functionality to rebuild this cache)
53  if ($this->dependencyInjectionCache->getBackend() instanceof ‪ContainerBackend) {
55  $diCacheBackend = $this->dependencyInjectionCache->getBackend();
56  // We need to remove using the forceFlush method because the DI cache backend disables the flush method
57  $diCacheBackend->forceFlush();
58  }
59 
60  // From this point on, the code may fatal, if some broken extension is loaded.
61  $this->lateBootService->loadExtLocalconfDatabaseAndExtTables();
62 
63  $extensionCaches = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
64  // Loose comparison on purpose to allow changed ordering of the array
65  if ($baseCaches != $extensionCaches) {
66  // When configuration has changed during loading of extensions (due to ext_localconf.php), flush all caches again
67  $this->‪flushCaches(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
68  }
69  }
70 
79  private function ‪flushCaches(array $cacheConfiguration): void
80  {
81  $cacheManager = new ‪CacheManager();
82  $cacheManager->setCacheConfigurations($cacheConfiguration);
83  $cacheManager->flushCaches();
84  }
85 }
‪TYPO3\CMS\Core\DependencyInjection\Cache\ContainerBackend
Definition: ContainerBackend.php:26
‪TYPO3\CMS\Install\Service\ClearCacheService\flushCaches
‪flushCaches(array $cacheConfiguration)
Definition: ClearCacheService.php:79
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Install\Service\LateBootService
Definition: LateBootService.php:27
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Install\Service\ClearCacheService\__construct
‪__construct(private readonly LateBootService $lateBootService, private readonly FrontendInterface $dependencyInjectionCache)
Definition: ClearCacheService.php:28
‪TYPO3\CMS\Install\Service\ClearCacheService\clearAll
‪clearAll()
Definition: ClearCacheService.php:46
‪TYPO3\CMS\Install\Service\ClearCacheService
Definition: ClearCacheService.php:27
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:16