@@ -194,6 +194,13 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra
194194 */
195195 private ResponseHttp $ response ;
196196
197+ /**
198+ * Property used to cache the results of the isCacheable() method.
199+ *
200+ * @var bool|null
201+ */
202+ private ?bool $ isCacheableCache = null ;
203+
197204 /**
198205 * @param ProcessorFactory $processorFactory
199206 * @param ManagerInterface $eventManager
@@ -349,6 +356,7 @@ public function generateXml()
349356 public function generateElements ()
350357 {
351358 \Magento \Framework \Profiler::start (__CLASS__ . ':: ' . __METHOD__ );
359+ $ this ->isCacheableCache = null ;
352360 $ cacheId = 'structure_ ' . $ this ->getUpdate ()->getCacheId ();
353361 $ result = $ this ->cache ->load ($ cacheId );
354362 if ($ result ) {
@@ -1182,18 +1190,22 @@ protected function _prepareMessageGroup($messageGroups)
11821190 */
11831191 public function isCacheable ()
11841192 {
1185- $ this ->build ();
1186- $ elements = $ this ->getXml ()->xpath ('// ' . Element::TYPE_BLOCK . '[@cacheable="false"] ' );
1187- $ cacheable = $ this ->cacheable ;
1188- foreach ($ elements as $ element ) {
1189- $ blockName = $ element ->getBlockName ();
1190- if ($ blockName !== false && $ this ->structure ->hasElement ($ blockName )) {
1191- $ cacheable = false ;
1192- break ;
1193+ if ($ this ->isCacheableCache === null ) {
1194+ $ this ->build ();
1195+ $ elements = $ this ->getXml ()->xpath ('// ' . Element::TYPE_BLOCK . '[@cacheable="false"] ' );
1196+ $ cacheable = $ this ->cacheable ;
1197+ foreach ($ elements as $ element ) {
1198+ $ blockName = $ element ->getBlockName ();
1199+ if ($ blockName !== false && $ this ->structure ->hasElement ($ blockName )) {
1200+ $ cacheable = false ;
1201+ break ;
1202+ }
11931203 }
1204+
1205+ $ this ->isCacheableCache = $ cacheable ;
11941206 }
11951207
1196- return $ cacheable ;
1208+ return $ this -> isCacheableCache ;
11971209 }
11981210
11991211 /**
0 commit comments