Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konafets/87f74d86c06ffbe78f16 to your computer and use it in GitHub Desktop.
Save Konafets/87f74d86c06ffbe78f16 to your computer and use it in GitHub Desktop.
public function clear_cacheCmd($cacheCmd) {
if (is_object($this->BE_USER)) {
$this->BE_USER->writelog(3, 1, 0, 0, 'User %s has cleared the cache (cacheCmd=%s)', array($this->BE_USER->user['username'], $cacheCmd));
}
// Clear cache for either ALL pages or ALL tables!
switch (strtolower($cacheCmd)) {
case 'pages':
if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
}
break;
case 'all':
if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
// Clear cache group "all" of caching framework caches
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('all');
$GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
// Clearing additional cache tables:
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'] as $tableName) {
GeneralUtility::deprecationLog('Hook clearAllCache_additionalTables in DataHandler is deprecated in 6.2 and will be removed two versions later. Use the caching framework with database backend instead.');
if (!preg_match('/[^[:alnum:]_]/', $tableName) && substr($tableName, -5) === 'cache') {
$GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($tableName);
} else {
throw new \RuntimeException('TYPO3 Fatal Error: Trying to flush table "' . $tableName . '" with "Clear All Cache"', 1270853922);
}
}
}
}
break;
case 'temp_cached':
case 'system':
if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')
|| ((bool) $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === TRUE && $this->admin)) {
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
}
break;
}
$tagsToFlush = array();
// Clear cache for a page ID!
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($cacheCmd)) {
$list_cache = array($cacheCmd);
// Call pre-processing function for clearing of cache for page ids:
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) {
$_params = array('pageIdArray' => &$list_cache, 'cacheCmd' => $cacheCmd, 'functionID' => 'clear_cacheCmd()');
// Returns the array of ids to clear, FALSE if nothing should be cleared! Never an empty array!
GeneralUtility::callUserFunction($funcName, $_params, $this);
}
}
// Delete cache for selected pages:
if (is_array($list_cache)) {
foreach ($list_cache as $pageId) {
$tagsToFlush[] = 'pageId_' . (int)$pageId;
}
}
}
// flush cache by tag
if (GeneralUtility::isFirstPartOfStr(strtolower($cacheCmd), 'cachetag:')) {
$cacheTag = substr($cacheCmd, 9);
$tagsToFlush[] = $cacheTag;
}
// process caching framwork operations
if (count($tagsToFlush) > 0) {
foreach (array_unique($tagsToFlush) as $tag) {
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroupByTag('pages', $tag);
}
}
// Call post processing function for clear-cache:
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) {
$_params = array('cacheCmd' => strtolower($cacheCmd));
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment