diff -Nuar a/vendor/magento/framework/View/Layout.php b/vendor/magento/framework/View/Layout.php index 0a4ded9b0cf..7af460f2f41 100644 --- a/vendor/magento/framework/View/Layout.php +++ b/vendor/magento/framework/View/Layout.php @@ -36,6 +36,11 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra const LAYOUT_NODE = ''; /** + * Default cache life time + */ + private const DEFAULT_CACHE_LIFETIME = 31536000; + + /** * Layout Update module * * @var \Magento\Framework\View\Layout\ProcessorInterface @@ -172,6 +177,10 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * @var SerializerInterface */ private $serializer; + /** + * @var int + */ + private $cacheLifetime; /** * @param Layout\ProcessorFactory $processorFactory @@ -188,6 +197,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra * @param \Psr\Log\LoggerInterface $logger * @param bool $cacheable * @param SerializerInterface|null $serializer + * @param int|null $cacheLifetime */ public function __construct( Layout\ProcessorFactory $processorFactory, @@ -203,7 +213,8 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra AppState $appState, Logger $logger, $cacheable = true, - SerializerInterface $serializer = null + SerializerInterface $serializer = null, + ?int $cacheLifetime = null ) { $this->_elementClass = \Magento\Framework\View\Layout\Element::class; $this->_renderingOutput = new \Magento\Framework\DataObject(); @@ -222,6 +233,7 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra $this->generatorContextFactory = $generatorContextFactory; $this->appState = $appState; $this->logger = $logger; + $this->cacheLifetime = $cacheLifetime ?? self::DEFAULT_CACHE_LIFETIME; } /** @@ -338,7 +350,8 @@ class Layout extends \Magento\Framework\Simplexml\Config implements \Magento\Fra 'pageConfigStructure' => $this->getReaderContext()->getPageConfigStructure()->__toArray(), 'scheduledStructure' => $this->getReaderContext()->getScheduledStructure()->__toArray(), ]; - $this->cache->save($this->serializer->serialize($data), $cacheId, $this->getUpdate()->getHandles()); + $handles = $this->getUpdate()->getHandles(); + $this->cache->save($this->serializer->serialize($data), $cacheId, $handles, $this->cacheLifetime); } $generatorContext = $this->generatorContextFactory->create( diff -Nuar a/vendor/magento/framework/View/Model/Layout/Merge.php b/vendor/magento/framework/View/Model/Layout/Merge.php index fe79976039a..239d4167043 100644 --- a/vendor/magento/framework/View/Model/Layout/Merge.php +++ b/vendor/magento/framework/View/Model/Layout/Merge.php @@ -48,6 +48,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface const PAGE_LAYOUT_CACHE_SUFFIX = 'page_layout_merged'; /** + * Default cache life time + */ + private const DEFAULT_CACHE_LIFETIME = 31536000; + + /** * @var \Magento\Framework\View\Design\ThemeInterface */ private $theme; @@ -169,6 +174,10 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * @var ReadFactory */ private $readFactory; + /** + * @var int + */ + private $cacheLifetime; /** * Init merge model @@ -182,10 +191,11 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface * @param \Magento\Framework\View\Model\Layout\Update\Validator $validator * @param \Psr\Log\LoggerInterface $logger * @param ReadFactory $readFactory - * @param \Magento\Framework\View\Design\ThemeInterface $theme Non-injectable theme instance + * @param \Magento\Framework\View\Design\ThemeInterface|null $theme Non-injectable theme instance * @param string $cacheSuffix - * @param LayoutCacheKeyInterface $layoutCacheKey + * @param LayoutCacheKeyInterface|null $layoutCacheKey * @param SerializerInterface|null $serializer + * @param int|null $cacheLifetime * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -201,7 +211,8 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface \Magento\Framework\View\Design\ThemeInterface $theme = null, $cacheSuffix = '', LayoutCacheKeyInterface $layoutCacheKey = null, - SerializerInterface $serializer = null + SerializerInterface $serializer = null, + ?int $cacheLifetime = null ) { $this->theme = $theme ?: $design->getDesignTheme(); $this->scope = $scopeResolver->getScope(); @@ -216,6 +227,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface $this->layoutCacheKey = $layoutCacheKey ?: \Magento\Framework\App\ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class); $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); + $this->cacheLifetime = $cacheLifetime ?? self::DEFAULT_CACHE_LIFETIME; } /** @@ -749,7 +761,7 @@ class Merge implements \Magento\Framework\View\Layout\ProcessorInterface */ protected function _saveCache($data, $cacheId, array $cacheTags = []) { - $this->cache->save($data, $cacheId, $cacheTags, null); + $this->cache->save($data, $cacheId, $cacheTags, $this->cacheLifetime); } /**