Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/internal/Magento/Framework/View/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down