Commit 828f4262 authored by Benni Mack's avatar Benni Mack Committed by Anja Leichsenring
Browse files

[!!!][TASK] Streamline caching framework caches

Due to some heavy history on the caching framework, all
Database caches start with "cf_cache_", which is optimized
so they are only called e.g. "cache_pagesection" in the database tables.

In addition, the prefix "cache_" (in e.g. "cache_core") is unnecessary,
and also there due to legacy reasons, reading $this->getCache('cache_runtime')
seems very illogical.

The following caches have been renamed:
- cache_core => core
- cache_hash => hash
- cache_pages => pages
- cache_pagesection => pagesection
- cache_runtime => runtime
- cache_rootline => rootline
- cache_imagesizes => imagesizes

Old identifiers can still be called within PHP,
but the caching framework throws a deprecation message
on setting up such a cache.

A silent upgrade wizard will update one's LocalConfiguration
to use the new naming scheme.

The result is a cleaner, more readable and more streamlined
code base (we have caches like "extbase" or "assets" where
there is no prefix) and database structure.

The patch is breaking due to the change in the database tables.

Resolves: #88366
Releases: master
Change-Id: I13dcdb0d1bf78f0899615e850856de081b715358
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/59661

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent f998e96f
......@@ -72,7 +72,7 @@
"friendsofphp/php-cs-fixer": "^2.12.2",
"phpspec/prophecy": "^1.7.5",
"typo3/cms-styleguide": "~10.0.2",
"typo3/testing-framework": "~5.0.7"
"typo3/testing-framework": "~5.0.9"
},
"suggest": {
"ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d2fb17662a3d483385e72f9cd8937b60",
"content-hash": "870e3918ae3d5aa74326217313e58454",
"packages": [
{
"name": "cogpowered/finediff",
......@@ -5301,21 +5301,21 @@
},
{
"name": "typo3/testing-framework",
"version": "5.0.7",
"version": "5.0.9",
"source": {
"type": "git",
"url": "https://github.com/TYPO3/testing-framework.git",
"reference": "f6be4a637106eb90cb58491d67b92e50e1b6c8dc"
"reference": "bf7a5b7f1bc481ec791716a7fa33e3ed94215bdc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/f6be4a637106eb90cb58491d67b92e50e1b6c8dc",
"reference": "f6be4a637106eb90cb58491d67b92e50e1b6c8dc",
"url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/bf7a5b7f1bc481ec791716a7fa33e3ed94215bdc",
"reference": "bf7a5b7f1bc481ec791716a7fa33e3ed94215bdc",
"shasum": ""
},
"require": {
"mikey179/vfsstream": "~1.6.0",
"phpunit/phpunit": "^7.5.6",
"phpunit/phpunit": "^7.5.6 || ^8",
"typo3/cms-backend": "10.*.*@dev",
"typo3/cms-core": "10.*.*@dev",
"typo3/cms-extbase": "10.*.*@dev",
......@@ -5325,7 +5325,7 @@
"typo3fluid/fluid": "^2.5"
},
"suggest": {
"codeception/codeception": "^2.4",
"codeception/codeception": "^3",
"typo3/cms-styleguide": "^9.0"
},
"type": "library",
......@@ -5357,7 +5357,7 @@
"tests",
"typo3"
],
"time": "2019-03-23T16:23:15+00:00"
"time": "2019-05-16T08:49:46+00:00"
}
],
"aliases": [],
......
......@@ -203,6 +203,6 @@ class Avatar
*/
protected function getCache()
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
return GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
}
}
......@@ -55,7 +55,7 @@ class TsConfigParser extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
$this->rootLine = $rootLine;
$hash = md5($type . ':' . $TStext);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
$cachedContent = $cache->get($hash);
if (is_array($cachedContent)) {
$storedData = $cachedContent[0];
......
......@@ -96,7 +96,7 @@ class FormEngineUtility
*/
public static function getTSconfigForTableRow($table, $row, $field = '')
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$cache = $runtimeCache->get('formEngineUtilityTsConfigForTableRow') ?: [];
$cacheIdentifier = $table . ':' . $row['uid'];
if (!isset($cache[$cacheIdentifier])) {
......
......@@ -326,7 +326,7 @@ class BackendUtility
*/
public static function BEgetRootLine($uid, $clause = '', $workspaceOL = false, array $additionalFields = [])
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$beGetRootLineCache = $runtimeCache->get('backendUtilityBeGetRootLine') ?: [];
$output = [];
$pid = $uid;
......@@ -401,7 +401,7 @@ class BackendUtility
*/
protected static function getPageForRootline($uid, $clause, $workspaceOL, array $additionalFields = [])
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$pageForRootlineCache = $runtimeCache->get('backendUtilityPageForRootLine') ?: [];
$ident = $uid . '-' . $clause . '-' . $workspaceOL . ($additionalFields ? '-' . md5(implode(',', $additionalFields)) : '');
if (is_array($pageForRootlineCache[$ident] ?? false)) {
......@@ -3156,7 +3156,7 @@ class BackendUtility
*/
public static function getTSCpidCached($table, $uid, $pid)
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$firstLevelCache = $runtimeCache->get('backendUtilityTscPidCached') ?: [];
$key = $table . ':' . $uid . ':' . $pid;
if (!isset($firstLevelCache[$key])) {
......@@ -3219,7 +3219,7 @@ class BackendUtility
*/
protected static function getRuntimeCache()
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
return GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
}
/**
......
......@@ -62,7 +62,7 @@ class TcaSelectItemsTest extends UnitTestCase
$cacheManagerProphecy = $this->prophesize(CacheManager::class);
$cacheProphecy = $this->prophesize(FrontendInterface::class);
$cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheProphecy->reveal());
$cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal());
$cacheProphecy->get(Argument::cetera())->willReturn(false);
$cacheProphecy->set(Argument::cetera())->willReturn(false);
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
......
......@@ -40,7 +40,7 @@ class InlineStackProcessorTest extends UnitTestCase
parent::setUp();
$cacheManagerProphecy = $this->prophesize(CacheManager::class);
$cacheProphecy = $this->prophesize(FrontendInterface::class);
$cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheProphecy->reveal());
$cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal());
$cacheProphecy->get(Argument::cetera())->willReturn(false);
$cacheProphecy->set(Argument::cetera())->willReturn(false);
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
......
......@@ -1041,10 +1041,10 @@ class BackendUtilityTest extends UnitTestCase
$cacheManagerProphecy = $this->prophesize(CacheManager::class);
$cacheProphecy = $this->prophesize(FrontendInterface::class);
$cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheProphecy->reveal());
$cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal());
$cacheHashProphecy = $this->prophesize(FrontendInterface::class);
$cacheManagerProphecy->hasCache('extbase')->willReturn(false);
$cacheManagerProphecy->getCache('cache_hash')->willReturn($cacheHashProphecy->reveal());
$cacheManagerProphecy->getCache('hash')->willReturn($cacheHashProphecy->reveal());
$cacheProphecy->has(Argument::cetera())->willReturn(false);
$cacheProphecy->get(Argument::cetera())->willReturn(false);
$cacheProphecy->set(Argument::cetera())->willReturn(false);
......
......@@ -1298,7 +1298,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
$this->userTS_text = implode(LF . '[GLOBAL]' . LF, $this->TSdataArray);
// Parsing the user TSconfig (or getting from cache)
$hash = md5('userTS:' . $this->userTS_text);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
$parseObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
$parseObj->parse($this->userTS_text);
$this->userTS = $parseObj->setup;
......@@ -1555,7 +1555,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
*/
public function getFileMountRecords()
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$fileMountRecordCache = $runtimeCache->get('backendUserAuthenticationFileMountRecords') ?: [];
if (!empty($fileMountRecordCache)) {
......
......@@ -64,8 +64,8 @@ class Typo3DatabaseBackend extends AbstractBackend implements TaggableBackendInt
public function setCache(FrontendInterface $cache)
{
parent::setCache($cache);
$this->cacheTable = 'cf_' . $this->cacheIdentifier;
$this->tagsTable = 'cf_' . $this->cacheIdentifier . '_tags';
$this->cacheTable = 'cache_' . $this->cacheIdentifier;
$this->tagsTable = 'cache_' . $this->cacheIdentifier . '_tags';
$this->maximumLifetime = self::FAKED_UNLIMITED_EXPIRE - $GLOBALS['EXEC_TIME'];
}
......
......@@ -127,6 +127,11 @@ class CacheManager implements SingletonInterface
*/
public function getCache($identifier)
{
// Fallback layer, will be removed in TYPO3 v11.0.
if (strpos($identifier, 'cache_') === 0) {
trigger_error('Accessing a cache with the "cache_" prefix as in "' . $identifier . '" is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
$identifier = substr($identifier, 6);
}
if ($this->hasCache($identifier) === false) {
throw new NoSuchCacheException('A cache with identifier "' . $identifier . '" does not exist.', 1203699034);
}
......@@ -144,6 +149,11 @@ class CacheManager implements SingletonInterface
*/
public function hasCache($identifier)
{
// Fallback layer, will be removed in TYPO3 v11.0.
if (strpos($identifier, 'cache_') === 0) {
trigger_error('Accessing a cache with the "cache_" prefix as in "' . $identifier . '" is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
$identifier = substr($identifier, 6);
}
return isset($this->caches[$identifier]) || isset($this->cacheConfigurations[$identifier]);
}
......
......@@ -48,6 +48,10 @@ abstract class AbstractFrontend implements FrontendInterface
if (preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) !== 1) {
throw new \InvalidArgumentException('"' . $identifier . '" is not a valid cache identifier.', 1203584729);
}
if (strpos($identifier, 'cache_') === 0) {
trigger_error('Setting up a cache as in "' . $identifier . '" with the "cache_" prefix is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
$identifier = substr($identifier, 6);
}
$this->identifier = $identifier;
$this->backend = $backend;
$this->backend->setCache($this);
......
......@@ -199,6 +199,6 @@ class SiteConfiguration
*/
protected function getCache(): FrontendInterface
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
return GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
}
}
......@@ -86,7 +86,7 @@ class Bootstrap
$disableCaching = $failsafe ? true : false;
$logManager = new LogManager($requestId);
$coreCache = static::createCache('cache_core', $disableCaching);
$coreCache = static::createCache('core', $disableCaching);
$packageManager = static::createPackageManager(
$failsafe ? FailsafePackageManager::class : PackageManager::class,
$coreCache
......@@ -317,7 +317,7 @@ class Bootstrap
public static function loadTypo3LoadedExtAndExtLocalconf($allowCaching = true, FrontendInterface $coreCache = null)
{
if ($allowCaching) {
$coreCache = $coreCache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
$coreCache = $coreCache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
}
ExtensionManagementUtility::loadExtLocalconf($allowCaching, $coreCache);
}
......@@ -543,7 +543,7 @@ class Bootstrap
public static function loadBaseTca(bool $allowCaching = true, FrontendInterface $coreCache = null)
{
if ($allowCaching) {
$coreCache = $coreCache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
$coreCache = $coreCache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
}
ExtensionManagementUtility::loadBaseTca($allowCaching, $coreCache);
}
......@@ -608,7 +608,7 @@ class Bootstrap
$cacheIdentifier = 'BackendRoutesFromPackages_' . sha1(TYPO3_version . Environment::getProjectPath() . 'BackendRoutesFromPackages');
/** @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $codeCache */
$codeCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('cache_core');
$codeCache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('core');
$routesFromPackages = [];
if ($codeCache->has($cacheIdentifier)) {
// substr is necessary, because the php frontend wraps php code around the cache value
......
......@@ -7980,7 +7980,7 @@ class DataHandler implements LoggerAwareInterface
*
* The following cache_* are intentionally not cleared by 'all'
*
* - cache_imagesizes: Clearing this table would cause a lot of unneeded
* - 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"
......@@ -8344,7 +8344,7 @@ class DataHandler implements LoggerAwareInterface
*/
protected function getRuntimeCache()
{
return $this->getCacheManager()->getCache('cache_runtime');
return $this->getCacheManager()->getCache('runtime');
}
/**
......
......@@ -143,7 +143,7 @@ class ConnectionPool
$connectionParams['charset'] = 'utf8';
}
// Force consistent handling of binary objects across datbase platforms
// Force consistent handling of binary objects across database platforms
// MySQL returns strings by default, PostgreSQL streams.
if (strpos($connectionParams['driver'], 'pdo_') === 0) {
$connectionParams['driverOptions'][\PDO::ATTR_STRINGIFY_FETCHES] = true;
......
......@@ -157,7 +157,7 @@ class ReferenceIndex implements LoggerAwareInterface
*/
public function __construct()
{
$this->runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
$this->runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
}
/**
......
......@@ -26,7 +26,7 @@ class ProviderConfigurationLoader
PackageManager::class,
GeneralUtility::makeInstance(DependencyOrderingService::class)
);
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
if ($cache->has($this->cacheIdentifier)) {
/** @noinspection PhpUndefinedMethodInspection the method require() will be added to the interface in TYPO3 v10.0 */
......
......@@ -76,6 +76,6 @@ class SiteDataHandlerCacheHook
*/
protected function getCache(): FrontendInterface
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
return GeneralUtility::makeInstance(CacheManager::class)->getCache('core');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment