[TASK] Drastically reduce TS re-parsing in TemplatePaths 10/50510/8
authorClaus Due <claus@namelesscoder.net>
Sat, 5 Nov 2016 15:16:35 +0000 (16:16 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sun, 6 Nov 2016 05:47:19 +0000 (06:47 +0100)
This change implements a runtime cache which stores the view
configuration for extension keys. This
avoids calling removeDotsFromTS and other methods more
than one time per configuration.

Change-Id: I551fd8526d9a5576e22edaf45742ccb35c2f3aba
Fixes: #78580
Releases: master
Reviewed-on: https://review.typo3.org/50510
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/fluid/Classes/View/TemplatePaths.php

index f4b2efb..0ec2d0c 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Fluid\View;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
@@ -77,6 +79,12 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
         if (empty($extensionKey)) {
             return [];
         }
+        $cache = $this->getRuntimeCache();
+        $cacheIdentifier = 'viewpaths_' . $extensionKey;
+        $configuration = $cache->get($cacheIdentifier);
+        if (!empty($configuration)) {
+            return $configuration;
+        }
 
         $resources = $this->getExtensionPrivateResourcesPath($extensionKey);
         $paths = [
@@ -113,10 +121,19 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
             }
         }
 
+        $cache->set($cacheIdentifier, $paths);
         return $paths;
     }
 
     /**
+     * @return VariableFrontend
+     */
+    protected function getRuntimeCache()
+    {
+        return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
+    }
+
+    /**
      * @param string|array $path
      * @return string
      */