diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php index 8b1c159..c06dfe6 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php @@ -62,6 +62,13 @@ class ContextualLinkManager extends DefaultPluginManager implements ContextualLi protected $accessManager; /** + * A static cache of all the contextual link plugins by group name. + * + * @var array + */ + protected $pluginsByGroup; + + /** * Constructs a new ContextualLinkManager instance. * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver @@ -106,8 +113,12 @@ public function processDefinition(&$definition, $plugin_id) { * {@inheritdoc} */ public function getContextualLinkPluginsByGroup($group_name) { - if ($cache = $this->cacheBackend->get($this->cacheKey . ':' . $group_name)) { + if (isset($this->pluginsByGroup[$group_name])) { + $contextual_links = $this->pluginsByGroup[$group_name]; + } + elseif ($cache = $this->cacheBackend->get($this->cacheKey . ':' . $group_name)) { $contextual_links = $cache->data; + $this->pluginsByGroup[$group_name] = $contextual_links; } else { $contextual_links = array(); @@ -117,6 +128,7 @@ public function getContextualLinkPluginsByGroup($group_name) { } } $this->cacheBackend->set($this->cacheKey . ':' . $group_name, $contextual_links); + $this->pluginsByGroup[$group_name] = $contextual_links; } return $contextual_links; } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index 229798f..e7bef33 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -189,6 +189,11 @@ public function testGetContextualLinkPluginsByGroupWithCache() { $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group1'); $this->assertEquals($definitions, $result); + + // Ensure that the static cache works, so no second cache get is executed. + + $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group1'); + $this->assertEquals($definitions, $result); } /**