diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index 3bc42f846a819..5851bb4be2d58 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -193,6 +193,11 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra */ private ResponseHttp $response; + /** + * Property used to cache the results of the isCacheable() method. + */ + private bool|null $isCacheableCache = null; + /** * @param ProcessorFactory $processorFactory * @param ManagerInterface $eventManager @@ -1138,18 +1143,22 @@ protected function _prepareMessageGroup($messageGroups) */ public function isCacheable() { - $this->build(); - $elements = $this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]'); - $cacheable = $this->cacheable; - foreach ($elements as $element) { - $blockName = $element->getBlockName(); - if ($blockName !== false && $this->structure->hasElement($blockName)) { - $cacheable = false; - break; + if (!isset($this->isCacheableCache)) { + $this->build(); + $elements = $this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]'); + $cacheable = $this->cacheable; + foreach ($elements as $element) { + $blockName = $element->getBlockName(); + if ($blockName !== false && $this->structure->hasElement($blockName)) { + $cacheable = false; + break; + } } + + $this->isCacheableCache = $cacheable; } - return $cacheable; + return $this->isCacheableCache; } /**