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
27 changes: 18 additions & 9 deletions lib/internal/Magento/Framework/View/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using use comparator here? $this->isCacheableCache === null
We are sure that isCacheableCache property exists, so we can avoid this check

$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