diff --git a/vendor/magento/framework/View/Model/Layout/Merge.php b/vendor/magento/framework/View/Model/Layout/Merge.php index dbd6cc1ea548d..83be4ef0f2c33 100644 --- a/vendor/magento/framework/View/Model/Layout/Merge.php +++ b/vendor/magento/framework/View/Model/Layout/Merge.php @@ -11,6 +11,7 @@ use Magento\Framework\Filesystem\DriverPool; use Magento\Framework\Filesystem\File\ReadFactory; use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\View\EntitySpecificHandlesList; use Magento\Framework\View\Layout\LayoutCacheKeyInterface; use Magento\Framework\View\Model\Layout\Update\Validator; @@ -179,6 +180,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface */ private $cacheLifetime; + /** + * @var EntitySpecificHandlesList + */ + private EntitySpecificHandlesList $entitySpecificHandlesList; + /** * Init merge model * @@ -196,6 +202,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * @param LayoutCacheKeyInterface|null $layoutCacheKey * @param SerializerInterface|null $serializer * @param int|null $cacheLifetime + * @param EntitySpecificHandlesList|null $entitySpecificHandlesList * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -212,7 +219,8 @@ public function __construct( $cacheSuffix = '', ?LayoutCacheKeyInterface $layoutCacheKey = null, ?SerializerInterface $serializer = null, - ?int $cacheLifetime = null + ?int $cacheLifetime = null, + ?EntitySpecificHandlesList $entitySpecificHandlesList = null ) { $this->theme = $theme ?: $design->getDesignTheme(); $this->scope = $scopeResolver->getScope(); @@ -228,6 +236,8 @@ public function __construct( ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class); $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->cacheLifetime = $cacheLifetime ?? self::DEFAULT_CACHE_LIFETIME; + $this->entitySpecificHandlesList = $entitySpecificHandlesList + ?: ObjectManager::getInstance()->get(EntitySpecificHandlesList::class); } /** @@ -978,8 +988,21 @@ public function getScope() public function getCacheId() { $layoutCacheKeys = $this->layoutCacheKey->getCacheKeys(); + $handles = $this->getHandles(); + $entitySpecificHandles = $this->entitySpecificHandlesList->getHandles(); + if (!empty($entitySpecificHandles)) { + $entitySpecificHandles = array_flip($entitySpecificHandles); + $handles = array_values( + array_filter( + $handles, + function (string $handle) use ($entitySpecificHandles): bool { + return !isset($entitySpecificHandles[$handle]) || (bool)$this->getDbUpdateString($handle); + } + ) + ); + } // phpcs:ignore Magento2.Security.InsecureFunction - return $this->generateCacheId(md5(implode('|', array_merge($this->getHandles(), $layoutCacheKeys)))); + return $this->generateCacheId(md5(implode('|', array_merge($handles, $layoutCacheKeys)))); } /**