10
10
use Magento \Framework \App \MaintenanceMode ;
11
11
use Magento \Framework \App \ObjectManager ;
12
12
use Magento \Framework \App \ResponseInterface ;
13
+ use Magento \Framework \DataObject ;
13
14
use Magento \Framework \DataObject \IdentityInterface ;
15
+ use Magento \Framework \View \Element \BlockInterface ;
14
16
use Magento \Framework \View \Layout ;
15
17
use Magento \PageCache \Model \Config ;
16
18
use Magento \PageCache \Model \Spi \PageCacheTagsPreprocessorInterface ;
19
+ use function array_merge ;
20
+ use function array_unique ;
21
+ use function implode ;
17
22
18
23
/**
19
24
* Append cacheable pages response headers.
@@ -67,7 +72,7 @@ public function __construct(
67
72
* @param Layout $subject
68
73
* @return void
69
74
*/
70
- public function afterGenerateElements (Layout $ subject )
75
+ public function afterGenerateElements (Layout $ subject ): void
71
76
{
72
77
if ($ subject ->isCacheable () && !$ this ->maintenanceMode ->isOn () && $ this ->config ->isEnabled ()) {
73
78
$ this ->response ->setPublicHeaders ($ this ->config ->getTtl ());
@@ -78,22 +83,22 @@ public function afterGenerateElements(Layout $subject)
78
83
* Retrieve all identities from blocks for further cache invalidation.
79
84
*
80
85
* @param Layout $subject
81
- * @param mixed $result
82
- * @return mixed
86
+ * @param string $result
87
+ * @return string
83
88
*/
84
- public function afterGetOutput (Layout $ subject , $ result )
89
+ public function afterGetOutput (Layout $ subject , string $ result ): string
85
90
{
86
91
if ($ subject ->isCacheable () && $ this ->config ->isEnabled ()) {
87
92
$ tags = [];
88
93
$ isVarnish = $ this ->config ->getType () === Config::VARNISH ;
89
94
95
+ /** @var BlockInterface[] $block */
90
96
foreach ($ subject ->getAllBlocks () as $ block ) {
91
- if ($ block instanceof IdentityInterface ) {
92
- $ isEsiBlock = $ block ->getTtl () > 0 ;
93
- if ($ isVarnish && $ isEsiBlock ) {
94
- continue ;
97
+ if (! $ isVarnish || ( $ block instanceof DataObject && ! $ block -> getData ( ' ttl ' )) ) {
98
+ $ tags [] = ( array ) $ block ->getData ( ' cache_tags ' ) ;
99
+ if ($ block instanceof IdentityInterface ) {
100
+ $ tags [] = $ block -> getIdentities () ;
95
101
}
96
- $ tags [] = $ block ->getIdentities ();
97
102
}
98
103
}
99
104
$ tags = array_unique (array_merge ([], ...$ tags ));
0 commit comments