Skip to content
Open
Changes from 4 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
29 changes: 20 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 @@ -1167,18 +1174,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