From 66843ad6c2c81e508d88c89f83e49d9c093262c6 Mon Sep 17 00:00:00 2001 From: snezhig Date: Thu, 28 Oct 2021 15:53:00 +0300 Subject: [PATCH] Add static variable to reduce cache requests --- src/main/BitrixNeverInclude.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/BitrixNeverInclude.php b/src/main/BitrixNeverInclude.php index 733ca8f..7b82125 100644 --- a/src/main/BitrixNeverInclude.php +++ b/src/main/BitrixNeverInclude.php @@ -25,6 +25,7 @@ class BitrixNeverInclude */ protected static $excludedModulesIndex = null; + /** * Добавить исключение модулей из обработки * @@ -64,16 +65,23 @@ public static function registerModuleAutoload() */ public static function getClassMapping(): array { - $closure = function () { - $tools = new Tools(); - $tools->includeAllInstalledModules(); + static $mapping = null; + + //Для уменьшения запроса кеша. + if (is_null($mapping)) { + $closure = function () { + $tools = new Tools(); + $tools->includeAllInstalledModules(); - return $tools->getModuleByClassNameMapping($tools->getAutoLoadClasses()); - }; + return $tools->getModuleByClassNameMapping($tools->getAutoLoadClasses()); + }; + + $mapping = (new BitrixCache())->setTime(86400) + ->setTag(self::CACHE_TAG) + ->callback($closure); + } - return (new BitrixCache())->setTime(86400) - ->setTag(self::CACHE_TAG) - ->callback($closure); + return $mapping; } /**