[!!!][TASK] Consolidate extbase caches 73/59573/8
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 28 Jan 2019 08:51:30 +0000 (09:51 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Feb 2019 11:32:29 +0000 (12:32 +0100)
The caches of extbase have been consolidated as both of them shared the
same caching frontend. Cache identifiers `extbase_reflection` and
`extbase_datamapfactory_datamap` do no longer exist.

A single cache `extbase` is pre-configured and used for class schemata
and data maps instead.

Releases: master
Resolves: #87558
Change-Id: I4d7ec53cfd1b4900998fa2d01db1d8f2c1730633
Reviewed-on: https://review.typo3.org/59573
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-87558-ConsolidateExtbaseCaches.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Classes/Reflection/ReflectionService.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php

index e3e34cc..5fd971a 100644 (file)
@@ -1042,7 +1042,7 @@ class BackendUtilityTest extends UnitTestCase
         $cacheProphecy = $this->prophesize(FrontendInterface::class);
         $cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheProphecy->reveal());
         $cacheHashProphecy = $this->prophesize(FrontendInterface::class);
         $cacheProphecy = $this->prophesize(FrontendInterface::class);
         $cacheManagerProphecy->getCache('cache_runtime')->willReturn($cacheProphecy->reveal());
         $cacheHashProphecy = $this->prophesize(FrontendInterface::class);
-        $cacheManagerProphecy->hasCache('extbase_reflection')->willReturn(false);
+        $cacheManagerProphecy->hasCache('extbase')->willReturn(false);
         $cacheManagerProphecy->getCache('cache_hash')->willReturn($cacheHashProphecy->reveal());
         $cacheProphecy->has(Argument::cetera())->willReturn(false);
         $cacheProphecy->get(Argument::cetera())->willReturn(false);
         $cacheManagerProphecy->getCache('cache_hash')->willReturn($cacheHashProphecy->reveal());
         $cacheProphecy->has(Argument::cetera())->willReturn(false);
         $cacheProphecy->get(Argument::cetera())->willReturn(false);
index 886eb5c..13b1d14 100644 (file)
@@ -206,7 +206,7 @@ return [
                     'frontend' => \TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache::class,
                     'groups' => ['system'],
                 ],
                     'frontend' => \TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache::class,
                     'groups' => ['system'],
                 ],
-                'extbase_reflection' => [
+                'extbase' => [
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
                     'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
                     'options' => [
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
                     'backend' => \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class,
                     'options' => [
@@ -214,11 +214,6 @@ return [
                     ],
                     'groups' => ['system']
                 ],
                     ],
                     'groups' => ['system']
                 ],
-                'extbase_datamapfactory_datamap' => [
-                    'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
-                    'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
-                    'groups' => ['system'],
-                ],
             ],
         ],
         'defaultCategorizedTables' => '',
             ],
         ],
         'defaultCategorizedTables' => '',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-87558-ConsolidateExtbaseCaches.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-87558-ConsolidateExtbaseCaches.rst
new file mode 100644 (file)
index 0000000..c29de33
--- /dev/null
@@ -0,0 +1,50 @@
+.. include:: ../../Includes.txt
+
+=============================================
+Breaking: #87558 - Consolidate extbase caches
+=============================================
+
+See :issue:`87558`
+
+Description
+===========
+
+The caches of extbase have been consolidated as both of them shared the same caching frontend.
+Cache identifiers `extbase_reflection` and `extbase_datamapfactory_datamap` do no longer exist.
+
+A single cache `extbase` is pre-configured and used for class schemata and data maps instead.
+
+
+Impact
+======
+
+Adjusting the cache configuration of either `extbase_reflection`
+or `extbase_datamapfactory_datamap` will no longer have any effect.
+
+The installation may throw an error as well depending on the php error level configuration , if the no longer existing
+cache keys are written to without initializing them first.
+
+The following entries do no longer exist:
+
+* `$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_reflection']`
+* `$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['extbase_datamapfactory_datamap']`
+
+The following code code might throw an error depending on the php error level configuration:
+
+.. code-block:: php
+
+   $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['SYS']['cacheConfigurations']['extbase_reflection']['backend'] = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class;
+
+
+Affected Installations
+======================
+
+All installations that override the configuration of the caches `extbase_reflection` and `extbase_datamapfactory_datamap`.
+
+
+Migration
+=========
+
+Override new cache `extbase` in the same manner the former caches were overridden.
+
+.. index:: PHP-API, FullyScanned, ext:extbase
index 22d3ca7..c217b82 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Mapper;
  * The TYPO3 project - inspiring people to share!
  */
 
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
 use TYPO3\CMS\Extbase\Reflection\ClassSchema\Exception\NoSuchPropertyException;
 
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
 use TYPO3\CMS\Extbase\Reflection\ClassSchema\Exception\NoSuchPropertyException;
 
@@ -72,7 +73,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
         $this->objectManager = $objectManager;
         $this->cacheManager = $cacheManager;
 
         $this->objectManager = $objectManager;
         $this->cacheManager = $cacheManager;
 
-        $this->dataMapCache = $this->cacheManager->getCache('extbase_datamapfactory_datamap');
+        $this->dataMapCache = $this->cacheManager->getCache('extbase');
     }
 
     /**
     }
 
     /**
@@ -85,13 +86,16 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function buildDataMap($className)
     {
      */
     public function buildDataMap($className)
     {
+        $className = ltrim($className, '\\');
         if (isset($this->dataMaps[$className])) {
             return $this->dataMaps[$className];
         }
         if (isset($this->dataMaps[$className])) {
             return $this->dataMaps[$className];
         }
-        $dataMap = $this->dataMapCache->get(str_replace('\\', '%', $className));
+        $cacheIdentifierClassName = str_replace('\\', '', $className);
+        $cacheIdentifier = 'DataMap_' . $cacheIdentifierClassName . '_' . sha1(TYPO3_version . Environment::getProjectPath());
+        $dataMap = $this->dataMapCache->get($cacheIdentifier);
         if ($dataMap === false) {
             $dataMap = $this->buildDataMapInternal($className);
         if ($dataMap === false) {
             $dataMap = $this->buildDataMapInternal($className);
-            $this->dataMapCache->set(str_replace('\\', '%', $className), $dataMap);
+            $this->dataMapCache->set($cacheIdentifier, $dataMap);
         }
         $this->dataMaps[$className] = $dataMap;
         return $dataMap;
         }
         $this->dataMaps[$className] = $dataMap;
         return $dataMap;
index 5e4b77f..4498489 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Reflection;
  */
 
 use TYPO3\CMS\Core\Cache\CacheManager;
  */
 
 use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\SingletonInterface;
 
 /**
 use TYPO3\CMS\Core\SingletonInterface;
 
 /**
@@ -23,8 +24,10 @@ use TYPO3\CMS\Core\SingletonInterface;
  */
 class ReflectionService implements SingletonInterface
 {
  */
 class ReflectionService implements SingletonInterface
 {
-    const CACHE_IDENTIFIER = 'extbase_reflection';
-    const CACHE_ENTRY_IDENTIFIER = 'ClassSchematas';
+    /**
+     * @var string
+     */
+    private static $cacheEntryIdentifier;
 
     /**
      * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
 
     /**
      * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
@@ -61,11 +64,12 @@ class ReflectionService implements SingletonInterface
      */
     public function __construct(CacheManager $cacheManager = null)
     {
      */
     public function __construct(CacheManager $cacheManager = null)
     {
-        if ($cacheManager instanceof CacheManager && $cacheManager->hasCache(static::CACHE_IDENTIFIER)) {
+        if ($cacheManager instanceof CacheManager && $cacheManager->hasCache('extbase')) {
             $this->cachingEnabled = true;
             $this->cachingEnabled = true;
-            $this->dataCache = $cacheManager->getCache(static::CACHE_IDENTIFIER);
+            $this->dataCache = $cacheManager->getCache('extbase');
 
 
-            if (($classSchemata = $this->dataCache->get(static::CACHE_ENTRY_IDENTIFIER)) !== false) {
+            static::$cacheEntryIdentifier = 'ClassSchemata_' . sha1(TYPO3_version . Environment::getProjectPath());
+            if (($classSchemata = $this->dataCache->get(static::$cacheEntryIdentifier)) !== false) {
                 $this->classSchemata = $classSchemata;
             }
         }
                 $this->classSchemata = $classSchemata;
             }
         }
@@ -74,7 +78,7 @@ class ReflectionService implements SingletonInterface
     public function __destruct()
     {
         if ($this->dataCacheNeedsUpdate && $this->cachingEnabled) {
     public function __destruct()
     {
         if ($this->dataCacheNeedsUpdate && $this->cachingEnabled) {
-            $this->dataCache->set(static::CACHE_ENTRY_IDENTIFIER, $this->classSchemata);
+            $this->dataCache->set(static::$cacheEntryIdentifier, $this->classSchemata);
         }
     }
 
         }
     }
 
index 9a31645..a4b97ca 100644 (file)
@@ -79,6 +79,16 @@ return [
             'Important-83768-RemoveReferrerCheck.rst',
         ],
     ],
             'Important-83768-RemoveReferrerCheck.rst',
         ],
     ],
+    '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'caching\'][\'cacheConfigurations\'][\'extbase_reflection\']' => [
+        'restFiles' => [
+            'Breaking-87558-ConsolidateExtbaseCaches.rst',
+        ],
+    ],
+    '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'caching\'][\'cacheConfigurations\'][\'extbase_datamapfactory_datamap\']' => [
+        'restFiles' => [
+            'Breaking-87558-ConsolidateExtbaseCaches.rst',
+        ],
+    ],
 
     // Hooks
     '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'t3lib/class.t3lib_befunc.php\'][\'getFlexFormDSClass\']' => [
 
     // Hooks
     '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'t3lib/class.t3lib_befunc.php\'][\'getFlexFormDSClass\']' => [