From b2bb8d33a238f01a9b5594feecd78d3e9b5c193b Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 21 Dec 2015 12:28:04 +0000
Subject: [PATCH] Issue #1443308 by cilefen, joseph.olstad, mikeytown2,
 joelpittet, btopro, alexpott, marcingy, jonhattan, stewsnooze, tstoeckler,
 penyaskito: Add static cache to module_load_include()

---
 core/lib/Drupal/Core/Extension/ModuleHandler.php | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php
index b9a9a3e4974c..05f1e4f37283 100644
--- a/core/lib/Drupal/Core/Extension/ModuleHandler.php
+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -89,6 +89,13 @@ class ModuleHandler implements ModuleHandlerInterface {
    */
   protected $root;
 
+  /**
+   * A list of module include file keys.
+   *
+   * @var array
+   */
+  protected $includeFileKeys = [];
+
   /**
    * Constructs a ModuleHandler object.
    *
@@ -263,14 +270,21 @@ public function loadInclude($module, $type, $name = NULL) {
     }
 
     $name = $name ?: $module;
+    $key = $type . ':' . $module . ':' . $name;
+    if (isset($this->includeFileKeys[$key])) {
+      return $this->includeFileKeys[$key];
+    }
     if (isset($this->moduleList[$module])) {
       $file = $this->root . '/' . $this->moduleList[$module]->getPath() . "/$name.$type";
       if (is_file($file)) {
         require_once $file;
+        $this->includeFileKeys[$key] = $file;
         return $file;
       }
+      else {
+        $this->includeFileKeys[$key] = FALSE;
+      }
     }
-
     return FALSE;
   }
 
-- 
GitLab