Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit e0dc54c

Browse files
committed
Merge pull request #45 from georgringer/master
[FEATURE] Allow to clear all caches except page caches
2 parents 0c2cd3e + 2cb2395 commit e0dc54c

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Classes/Cli/Dispatcher.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function runCommand($command) {
112112
$args = array_slice($this->cli_args['_DEFAULT'], 2);
113113
$method = new ReflectionMethod(get_class($this), $command);
114114

115-
//check number of required arguments
115+
//check number of required arguments
116116
if ($method->getNumberOfRequiredParameters() !== count($args)) {
117117
throw new InvalidArgumentException('Wrong number of arguments');
118118
}
@@ -177,6 +177,20 @@ public function cacheClearpagecacheCommand() {
177177
$this->outputLine('Page cache cleared');
178178
}
179179

180+
/**
181+
* Clear all caches except the page cache.
182+
* This is especially useful on big sites when you can't just drop the page cache
183+
*
184+
* @example ./cli_dispatch.phpsh coreapi cache:clearallexceptpagecache
185+
* @return void
186+
*/
187+
public function clearAllExceptPageCacheCommand() {
188+
$cacheApiService = $this->getCacheApiService();
189+
$clearedCaches = $cacheApiService->clearAllExceptPageCache();
190+
191+
$this->outputLine('Cleared caches: ' . implode(', ', $clearedCaches));
192+
}
193+
180194
/**
181195
* Database compare
182196
*

Classes/Command/CacheApiCommandController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ public function clearPageCacheCommand() {
6868

6969
$this->outputLine('Page cache has been cleared.');
7070
}
71+
72+
/**
73+
* Clear all caches except the page cache.
74+
* This is especially useful on big sites when you can't just drop the page cache
75+
*
76+
* @return void
77+
*/
78+
public function clearAllExceptPageCacheCommand() {
79+
/** @var $service Tx_Coreapi_Service_CacheApiService */
80+
$service = $this->objectManager->get('Tx_Coreapi_Service_CacheApiService');
81+
$clearedCaches = $service->clearAllExceptPageCache();
82+
83+
$this->outputLine('Cleared caches: ' . implode(', ', $clearedCaches));
84+
}
7185
}
7286

7387
?>

Classes/Service/CacheApiService.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ public function clearConfigurationCache() {
7777
}
7878
$this->tce->clear_cacheCmd('temp_cached');
7979
}
80+
81+
/**
82+
* Clear all caches except the page cache.
83+
* This is especially useful on big sites when you can't just drop the page cache
84+
*
85+
* @return array with list of cleared caches
86+
*/
87+
public function clearAllExceptPageCache() {
88+
$out = array();
89+
$cacheKeys = array_keys($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
90+
$ignoredCaches = array('cache_pages', 'cache_pagesection');
91+
92+
$toBeFlushed = array_diff($cacheKeys, $ignoredCaches);
93+
94+
/** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
95+
$cacheManager = $GLOBALS['typo3CacheManager'];
96+
foreach($cacheKeys as $cacheKey) {
97+
if ($cacheManager->hasCache($cacheKey)) {
98+
$out[] = $cacheKey;
99+
$singleCache = $cacheManager->getCache($cacheKey);
100+
$singleCache->flush();
101+
}
102+
}
103+
104+
return $toBeFlushed;
105+
}
80106
}
81107

82108
?>

0 commit comments

Comments
 (0)