diff --git a/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php b/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php index 6aff8aef2c2d9..18668208bcb69 100644 --- a/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php +++ b/app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php @@ -10,10 +10,15 @@ use Magento\Framework\App\MaintenanceMode; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ResponseInterface; +use Magento\Framework\DataObject; use Magento\Framework\DataObject\IdentityInterface; +use Magento\Framework\View\Element\BlockInterface; use Magento\Framework\View\Layout; use Magento\PageCache\Model\Config; use Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface; +use function array_merge; +use function array_unique; +use function implode; /** * Append cacheable pages response headers. @@ -67,7 +72,7 @@ public function __construct( * @param Layout $subject * @return void */ - public function afterGenerateElements(Layout $subject) + public function afterGenerateElements(Layout $subject): void { if ($subject->isCacheable() && !$this->maintenanceMode->isOn() && $this->config->isEnabled()) { $this->response->setPublicHeaders($this->config->getTtl()); @@ -78,22 +83,22 @@ public function afterGenerateElements(Layout $subject) * Retrieve all identities from blocks for further cache invalidation. * * @param Layout $subject - * @param mixed $result - * @return mixed + * @param string $result + * @return string */ - public function afterGetOutput(Layout $subject, $result) + public function afterGetOutput(Layout $subject, string $result): string { if ($subject->isCacheable() && $this->config->isEnabled()) { $tags = []; $isVarnish = $this->config->getType() === Config::VARNISH; + /** @var BlockInterface[] $block */ foreach ($subject->getAllBlocks() as $block) { - if ($block instanceof IdentityInterface) { - $isEsiBlock = $block->getTtl() > 0; - if ($isVarnish && $isEsiBlock) { - continue; + if (!$isVarnish || ($block instanceof DataObject && !$block->getData('ttl'))) { + $tags[] = (array) $block->getData('cache_tags'); + if ($block instanceof IdentityInterface) { + $tags[] = $block->getIdentities(); } - $tags[] = $block->getIdentities(); } } $tags = array_unique(array_merge([], ...$tags));