[TASK] Introduce cache for readLLfile() 06/52406/10
authorFaton Haliti <fha@systime.dk>
Mon, 10 Apr 2017 13:43:24 +0000 (15:43 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 14 May 2017 12:27:06 +0000 (14:27 +0200)
Cache the result of readLLfile() gives a better performance
for cases where readLLfile() is called often.

Resolves: #80788
Releases: master, 8.7
Change-Id: I59913c7c5124ebe54c567a0a7c126a32fdd60284
Reviewed-on: https://review.typo3.org/52406
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Kasper Ligaard <kasperligaard+typo3.org@gmail.com>
Reviewed-by: Faton Haliti <fha@systime.dk>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Localization/LanguageService.php

index fcc08c2..90e3a1c 100644 (file)
@@ -64,6 +64,13 @@ class LanguageService
     protected $languageDependencies = [];
 
     /**
+     * An internal cache for storing loaded files, see readLLfile()
+     *
+     * @var array
+     */
+    protected $languageFileCache = [];
+
+    /**
      * LanguageService constructor.
      */
     public function __construct()
@@ -295,6 +302,10 @@ class LanguageService
      */
     protected function readLLfile($fileRef)
     {
+        if (isset($this->languageFileCache[$fileRef . $this->lang])) {
+            return $this->languageFileCache[$fileRef . $this->lang];
+        }
+
         /** @var $languageFactory LocalizationFactory */
         $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
 
@@ -316,6 +327,8 @@ class LanguageService
                 ArrayUtility::mergeRecursiveWithOverrule($localLanguage[$this->lang], $tempLL[$language], true, false);
             }
         }
+        $this->languageFileCache[$fileRef . $this->lang] = $localLanguage;
+
         return $localLanguage;
     }