‪TYPO3CMS  10.4
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 
23 
29 {
30  private const ‪legacyDatabaseCacheTables = [
31  'cache_treelist',
32  ];
33 
37  private ‪$lateBootService;
38 
43 
44  public function ‪__construct(
47  ) {
48  $this->lateBootService = ‪$lateBootService;
49  $this->dependencyInjectionCache = ‪$dependencyInjectionCache;
50  }
51 
65  public function ‪clearAll()
66  {
67  // Low level flush of legacy database cache tables
68  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
69  foreach (self::legacyDatabaseCacheTables as $tableName) {
70  $connection = $connectionPool->getConnectionForTable($tableName);
71  $connection->truncate($tableName);
72  }
73 
74  // Flush all caches defined in TYPO3_CONF_VARS, but not the ones defined by extensions in ext_localconf.php
75  $baseCaches = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
76  $this->‪flushCaches($baseCaches);
77 
78  // Remove DI container cache (this might be removed in preference of functionality to rebuild this cache)
79  if ($this->dependencyInjectionCache->getBackend() instanceof ContainerBackend) {
81  $diCacheBackend = $this->dependencyInjectionCache->getBackend();
82  // We need to remove using the forceFlush method because the DI cache backend disables the flush method
83  $diCacheBackend->forceFlush();
84  }
85 
86  // From this point on, the code may fatal, if some broken extension is loaded.
87  $this->lateBootService->loadExtLocalconfDatabaseAndExtTables();
88 
89  $extensionCaches = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] ?? [];
90  // Loose comparison on purpose to allow changed ordering of the array
91  if ($baseCaches != $extensionCaches) {
92  // When configuration has changed during loading of extensions (due to ext_localconf.php), flush all caches again
93  $this->‪flushCaches(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
94  }
95  }
96 
107  private function ‪flushCaches(array $cacheConfiguration): void
108  {
109  $cacheManager = new CacheManager();
110  $cacheManager->setCacheConfigurations($cacheConfiguration);
111  $cacheManager->flushCaches();
112  }
113 }
‪TYPO3\CMS\Core\DependencyInjection\Cache\ContainerBackend
Definition: ContainerBackend.php:26
‪TYPO3\CMS\Install\Service\ClearCacheService\__construct
‪__construct(LateBootService $lateBootService, FrontendInterface $dependencyInjectionCache)
Definition: ClearCacheService.php:42
‪TYPO3\CMS\Install\Service\ClearCacheService\$dependencyInjectionCache
‪FrontendInterface $dependencyInjectionCache
Definition: ClearCacheService.php:40
‪TYPO3\CMS\Install\Service\ClearCacheService\flushCaches
‪flushCaches(array $cacheConfiguration)
Definition: ClearCacheService.php:105
‪TYPO3\CMS\Install\Service\ClearCacheService\$lateBootService
‪LateBootService $lateBootService
Definition: ClearCacheService.php:36
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Install\Service\ClearCacheService\legacyDatabaseCacheTables
‪const legacyDatabaseCacheTables
Definition: ClearCacheService.php:30
‪TYPO3\CMS\Install\Service\LateBootService
Definition: LateBootService.php:34
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Install\Service\ClearCacheService\clearAll
‪clearAll()
Definition: ClearCacheService.php:63
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Service\ClearCacheService
Definition: ClearCacheService.php:29
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:16