diff --git a/core/lib/Drupal/Component/ClassLoader/ApcClassLoader.php b/core/lib/Drupal/Component/ClassLoader/ApcClassLoader.php index 7664ee5a07..56a62b88be 100644 --- a/core/lib/Drupal/Component/ClassLoader/ApcClassLoader.php +++ b/core/lib/Drupal/Component/ClassLoader/ApcClassLoader.php @@ -26,14 +26,14 @@ class ApcClassLoader { * * @var string[] */ - protected $data = []; + protected $classmap = []; /** * A flag to whether the data should be written to disc. * * @var bool */ - protected $writeData = FALSE; + protected $writeClassMap = FALSE; /** * Constructor. @@ -98,33 +98,40 @@ public function loadClass($class) { * @return string|null */ public function findFile($class) { - if (!empty($this->data[$class])) { - return $this->data[$class]; + if (!empty($this->classmap[$class])) { + return $this->classmap[$class]; } - elseif (!isset($this->data) && $data = apcu_fetch($this->prefix)) { - $this->data = $data; + elseif (!isset($this->classmap) && $data = apcu_fetch($this->prefix)) { + $this->classmap = $data; } else { - $this->data[$class] = $this->decorated->findFile($class); - $this->writeData = TRUE; + $this->classmap[$class] = $this->decorated->findFile($class); + $this->writeClassMap = TRUE; } - return $this->data[$class]; + return $this->classmap[$class]; } /** * Passes through all unknown calls onto the decorated object. */ public function __call($method, $args) { - return call_user_func_array(array($this->decorated, $method), $args); + return call_user_func_array([$this->decorated, $method], $args); } /** * {@inheritdoc} */ public function __destruct() { - if ($this->writeData) { - apcu_store($this->prefix, $this->data); + if ($this->writeClassMap) { + // A different request might have loaded different classes, so let's merge + // the data to improve efficiency. + if ($previous_classmap = apcu_fetch($this->prefix)) { + $class_map = array_merge($this->classmap, $previous_classmap); + if ($class_map != $previous_classmap) { + apcu_store($this->prefix, $this->classmap); + } + } } }