diff --git a/typo3/sysext/core/Classes/Cache/CacheManager.php b/typo3/sysext/core/Classes/Cache/CacheManager.php index 469d499..79ee680 100644 --- a/typo3/sysext/core/Classes/Cache/CacheManager.php +++ b/typo3/sysext/core/Classes/Cache/CacheManager.php @@ -50,12 +50,22 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface { protected $cacheConfigurations = array(); /** + * used to flush caches of a specific group + * is an associative array containing the group identifier as key + * and the identifier as an array within that group + * groups are set via the cache configurations of each cache + * @var array + */ + protected $cacheGroups = array(); + + /** * @var array Default cache configuration as fallback */ protected $defaultCacheConfiguration = array( 'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend', - 'options' => array() + 'options' => array(), + 'groups' => array('unassigned') ); /** @@ -150,6 +160,45 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface { } /** + * Flushes all registered caches of a specific group + * + * @param string $groupIdentifier + * @return void + * @api + */ + public function flushCachesInGroup($groupIdentifier) { + $this->createAllCaches(); + if (isset($this->cacheGroups[$groupIdentifier])) { + foreach ($this->cacheGroups[$groupIdentifier] as $cacheIdentifier) { + if (isset($this->caches[$cacheIdentifier])) { + $this->caches[$cacheIdentifier]->flush(); + } + } + } + } + + /** + * Flushes entries tagged by the specified tag of all registered + * caches of a specific group. + * + * @param string $groupIdentifier + * @param string $tag Tag to search for + * @return void + * @api + */ + public function flushCachesInGroupByTag($groupIdentifier, $tag) { + $this->createAllCaches(); + if (isset($this->cacheGroups[$groupIdentifier])) { + foreach ($this->cacheGroups[$groupIdentifier] as $cacheIdentifier) { + if (isset($this->caches[$cacheIdentifier])) { + $this->caches[$cacheIdentifier]->flushByTag($tag); + } + } + } + } + + + /** * Flushes entries tagged by the specified tag of all registered * caches. * @@ -299,6 +348,7 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface { * * @param string $identifier * @return void + * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException when the groups parameter is not set */ protected function createCache($identifier) { if (isset($this->cacheConfigurations[$identifier]['frontend'])) { @@ -316,6 +366,20 @@ class CacheManager implements \TYPO3\CMS\Core\SingletonInterface { } else { $backendOptions = $this->defaultCacheConfiguration['options']; } + + // add the cache to the groups that it should be attached, or use the default ones + if (isset($this->cacheConfigurations[$identifier]['groups']) && is_array($this->cacheConfigurations[$identifier]['groups'])) { + $assignedGroups = $this->cacheConfigurations[$identifier]['groups']; + } else { + $assignedGroups = $this->defaultCacheConfiguration['groups']; + } + foreach ($assignedGroups as $groupIdentifier) { + if (!is_array($this->cacheGroups[$groupIdentifier])) { + $this->cacheGroups[$groupIdentifier] = array(); + } + $this->cacheGroups[$groupIdentifier][] = $identifier; + } + $this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions); } diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index ed2bd0a..884065e 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -6931,34 +6931,42 @@ class DataHandler { /** * Clears the cache based on the command $cacheCmd. * - * $cacheCmd='pages': Clears cache for all pages. Requires admin-flag to - * be set for BE_USER. + * $cacheCmd='pages' + * Clears cache for all pages and page-based caches inside the cache manager. + * Requires admin-flag to be set for BE_USER. * - * $cacheCmd='all': Clears all cache_tables. This is necessary if - * templates are updated. Requires admin-flag to be set for BE_USER. + * $cacheCmd='all' + * Clears all cache_tables. This is necessary if templates are updated. + * Requires admin-flag to be set for BE_USER. * - * $cacheCmd=[integer]: Clears cache for the page pointed to by $cacheCmd - * (an integer). + * The following cache_* are intentionally not cleared by 'all' * - * $cacheCmd='cacheTag:[string]': Flush page and pagesection cache by given tag + * - cache_md5params: RDCT redirects. + * - cache_imagesizes: Clearing this table would cause a lot of unneeded + * Imagemagick calls because the size informations have + * to be fetched again after clearing. + * - all caches inside the cache manager that are inside the group "system" + * - they are only needed to build up the core system and templates, + * use "temp_cached" or "system" to do that + * + * $cacheCmd=[integer] + * Clears cache for the page pointed to by $cacheCmd (an integer). * - * $cacheCmd='cacheId:[string]': Removes cache identifier from page and page section cache + * $cacheCmd='cacheTag:[string]' + * Flush page and pagesection cache by given tag + * + * $cacheCmd='cacheId:[string]' + * Removes cache identifier from page and page section cache * * Can call a list of post processing functions as defined in * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] * (numeric array with values being the function references, called by * GeneralUtility::callUserFunction()). * - * Note: The following cache_* are intentionally not cleared by - * $cacheCmd='all': - * - * - cache_md5params: RDCT redirects. - * - cache_imagesizes: Clearing this table would cause a lot of unneeded - * Imagemagick calls because the size informations have - * to be fetched again after clearing. * * @param string $cacheCmd The cache command, see above description * @return void + * @throws \RuntimeException */ public function clear_cacheCmd($cacheCmd) { if (is_object($this->BE_USER)) { @@ -6968,13 +6976,14 @@ class DataHandler { switch (strtolower($cacheCmd)) { case 'pages': if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) { - $this->internal_clearPageCache(); + $GLOBALS['typo3CacheManager']->flushCachesInGroup('pages'); } break; case 'all': if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) { // Clear all caching framework caches - $GLOBALS['typo3CacheManager']->flushCaches(); + $GLOBALS['typo3CacheManager']->flushCachesInGroup('pages'); + $GLOBALS['typo3CacheManager']->flushCachesInGroup('unassigned'); if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) { $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist'); } @@ -6989,12 +6998,16 @@ class DataHandler { } } } - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::removeCacheFiles(); + break; case 'temp_cached': - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::removeCacheFiles(); + case 'system': + if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system') || $this->BE_USER->getTSConfigVal('options.clearCache.all')) { + $GLOBALS['typo3CacheManager']->flushCachesInGroup('system'); + } break; } + $tagsToFlush = array(); // Clear cache for a page ID! if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($cacheCmd)) { @@ -7023,18 +7036,11 @@ class DataHandler { } // process caching framwork operations if (count($tagsToFlush) > 0) { - /** @var $pageCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */ - $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages'); - /** @var $pageSectionCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */ - $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection'); - /** @var $hashCache \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend */ - $hashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash'); foreach ($tagsToFlush as $tag) { - $pageCache->flushByTag($tag); - $pageSectionCache->flushByTag($tag); - $hashCache->flushByTag($tag); + $GLOBALS['typo3CacheManager']->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)); @@ -7148,11 +7154,11 @@ class DataHandler { * * @return void * @todo Define visibility + * @deprecated since TYPO3 CMS 6.2, remove two versions later */ public function internal_clearPageCache() { - if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) { - $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flush(); - } + GeneralUtility::logDeprecatedFunction('The DataHandler clearPageCache method is deprecated, use the cache manager directly.'); + $GLOBALS['typo3CacheManager']->flushGroups('pages'); } /** diff --git a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php index b7a7f3c..70b579c 100644 --- a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php +++ b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php @@ -1744,7 +1744,7 @@ tt_content.' . $key . $prefix . ' { } /** - * Remove cache files from php code cache, tagged with 'core' + * Remove cache files from php code cache, grouped by 'system' * * This removes the following cache entries: * - autoloader cache registry @@ -1759,9 +1759,7 @@ tt_content.' . $key . $prefix . ' { * @return void */ static public function removeCacheFiles() { - /** @var $codeCache \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend */ - $codeCache = $GLOBALS['typo3CacheManager']->getCache('cache_core'); - $codeCache->flush(); + $GLOBALS['typo3CacheManager']->flushCachesInGroup('system'); } /** diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php index 2c6f3ac..b940fbe 100644 --- a/typo3/sysext/core/Configuration/DefaultConfiguration.php +++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php @@ -132,51 +132,68 @@ return array( 'cache_core' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\PhpFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend', - 'options' => array() + 'options' => array( + 'defaultLifetime' => 0, + ), + 'groups' => array('system') ), 'cache_classes' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\StringFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend', - 'options' => array() + 'options' => array( + 'defaultLifetime' => 0, + ), + 'groups' => array('system') ), 'cache_hash' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend', - 'options' => array() + 'options' => array(), + 'groups' => array('pages') ), 'cache_pages' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend', 'options' => array( 'compression' => TRUE - ) + ), + 'groups' => array('pages') ), 'cache_pagesection' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend', 'options' => array( 'compression' => TRUE - ) + ), + 'groups' => array('pages') ), 'cache_phpcode' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\PhpFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\FileBackend', - 'options' => array() + 'options' => array( + 'defaultLifetime' => 0, + ), + 'groups' => array('system') ), 'cache_runtime' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend', - 'options' => array() + 'options' => array(), + 'groups' => array() ), 'cache_rootline' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend', - 'options' => array() + 'options' => array(), + 'groups' => array('pages') ), 't3lib_l10n' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', 'backend' => 'TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend', - 'options' => array(), + 'options' => array( + 'defaultLifetime' => 0, + ), + 'groups' => array('system') ), 'extbase_object' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', @@ -184,6 +201,7 @@ return array( 'options' => array( 'defaultLifetime' => 0, ), + 'groups' => array('system') ), 'extbase_reflection' => array( 'frontend' => 'TYPO3\CMS\Core\Cache\Frontend\VariableFrontend', @@ -191,6 +209,7 @@ return array( 'options' => array( 'defaultLifetime' => 0, ), + 'groups' => array('system') ), ), ), diff --git a/typo3/sysext/dbal/ext_localconf.php b/typo3/sysext/dbal/ext_localconf.php index 2d4458b..44c0c82 100644 --- a/typo3/sysext/dbal/ext_localconf.php +++ b/typo3/sysext/dbal/ext_localconf.php @@ -10,6 +10,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Recordlist\\RecordLis // Register caches if not already done in localconf.php or a previously loaded extension. if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dbal'] = array( - 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend' + 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend', + 'groups' => array() ); } diff --git a/typo3/sysext/extbase/ext_localconf.php b/typo3/sysext/extbase/ext_localconf.php index ec25f57..8b06fcf 100644 --- a/typo3/sysext/extbase/ext_localconf.php +++ b/typo3/sysext/extbase/ext_localconf.php @@ -7,10 +7,14 @@ require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbas require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'Classes/Utility/ExtensionUtility.php'; if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array( + 'groups' => array('system') + ); } if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array( + 'groups' => array('system') + ); } // We need to set the default implementation for Storage Backend & Query Settings diff --git a/typo3/sysext/fluid/ext_localconf.php b/typo3/sysext/fluid/ext_localconf.php index 9830ad9..dc648cb 100644 --- a/typo3/sysext/fluid/ext_localconf.php +++ b/typo3/sysext/fluid/ext_localconf.php @@ -6,6 +6,7 @@ if (!defined('TYPO3_MODE')) { if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template'])) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['fluid_template'] = array( 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend', - 'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend' + 'frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend', + 'groups' => array('system') ); } diff --git a/typo3/sysext/install/Classes/Service/SqlExpectedSchemaService.php b/typo3/sysext/install/Classes/Service/SqlExpectedSchemaService.php index 3e46828..626ec5f 100644 --- a/typo3/sysext/install/Classes/Service/SqlExpectedSchemaService.php +++ b/typo3/sysext/install/Classes/Service/SqlExpectedSchemaService.php @@ -112,11 +112,19 @@ class SqlExpectedSchemaService { */ public function getCachingFrameworkRequiredDatabaseSchema() { $cacheConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap'] = array( + 'groups' => array('system') + ); $extbaseObjectFakeName = uniqid('extbase_object'); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extbaseObjectFakeName] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection'] = array(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$extbaseObjectFakeName] = array( + 'groups' => array('system') + ); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection'] = array( + 'groups' => array('system') + ); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_typo3dbbackend_tablecolumns'] = array( + 'groups' => array('system') + ); /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */ $cacheManager = $GLOBALS['typo3CacheManager']; $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); diff --git a/typo3/sysext/workspaces/ext_localconf.php b/typo3/sysext/workspaces/ext_localconf.php index f07dff6..d73c735 100644 --- a/typo3/sysext/workspaces/ext_localconf.php +++ b/typo3/sysext/workspaces/ext_localconf.php @@ -29,7 +29,9 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_acc // Register workspaces cache if not already done in localconf.php or a previously loaded extension. if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['workspaces_cache'])) { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['workspaces_cache'] = array(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['workspaces_cache'] = array( + 'groups' => array('pages') + ); } \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig('options.workspaces.considerReferences = 1');