diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index 8950589a1aa83..86d18b927da0d 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -194,6 +194,13 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra */ private ResponseHttp $response; + /** + * Property used to cache the results of the isCacheable() method. + * + * @var bool|null + */ + private ?bool $isCacheableCache = null; + /** * @param ProcessorFactory $processorFactory * @param ManagerInterface $eventManager @@ -349,6 +356,7 @@ public function generateXml() public function generateElements() { \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__); + $this->isCacheableCache = null; $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { @@ -1167,18 +1175,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 ($this->isCacheableCache === null) { + $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; } /**