[TASK] Migrate getPagesTSconfig to runtime cache 51/55451/2
authorStefan Froemken <froemken@gmail.com>
Wed, 13 Sep 2017 12:11:14 +0000 (14:11 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 24 Jan 2018 16:09:06 +0000 (17:09 +0100)
BackendUtility::getPagesTSconfig() uses local
method static properties as cache.
This prevents dedicated flushing, which may
be needed in rare cases to prevent for instance
from exceeded memory during huge imports.
The patch switches that to cache framework
cache_runtime which is already used at other
places within BackendUtility.

Resolves: #82473
Related: #63629
Releases: master, 8.7
Change-Id: I4d54819f05a6c7b8ce175bc827b626277e2d4c04
Reviewed-on: https://review.typo3.org/55451
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 437b931..4de98f1 100644 (file)
@@ -1235,15 +1235,14 @@ class BackendUtility
      */
     public static function getPagesTSconfig($id, $rootLine = null, $returnPartArray = false)
     {
-        static $pagesTSconfig_cacheReference = [];
-        static $combinedTSconfig_cache = [];
-
         $id = (int)$id;
+
+        $cache = self::getRuntimeCache();
         if ($returnPartArray === false
             && $rootLine === null
-            && isset($pagesTSconfig_cacheReference[$id])
+            && $cache->has('pagesTsConfigIdToHash' . $id)
         ) {
-            return $combinedTSconfig_cache[$pagesTSconfig_cacheReference[$id]];
+            return $cache->get('pagesTsConfigHashToContent' . $cache->get('pagesTsConfigIdToHash' . $id));
         }
         $TSconfig = [];
         if (!is_array($rootLine)) {
@@ -1306,10 +1305,11 @@ class BackendUtility
         }
 
         if ($useCacheForCurrentPageId) {
-            if (!isset($combinedTSconfig_cache[$cacheHash])) {
-                $combinedTSconfig_cache[$cacheHash] = $TSconfig;
-            }
-            $pagesTSconfig_cacheReference[$id] = $cacheHash;
+            // Many pages end up with the same ts config. To reduce memory usage, the cache
+            // entries are a linked list: One or more pids point to content hashes which then
+            // contain the cached content.
+            $cache->set('pagesTsConfigHashToContent' . $cacheHash, $TSconfig, ['pagesTsConfig']);
+            $cache->set('pagesTsConfigIdToHash' . $id, $cacheHash, ['pagesTsConfig']);
         }
 
         return $TSconfig;