Skip to content

Commit 846b20c

Browse files
committed
ACP2E-3063: [Cloud] Cache is not getting invalidated.
- with test
1 parent 8231818 commit 846b20c

File tree

8 files changed

+34
-104
lines changed

8 files changed

+34
-104
lines changed

app/code/Magento/Catalog/Model/Category/LayoutCacheTagResolver.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public function getTags($object)
3535
{
3636
if ($this->isExistingCategoryLayoutChange($object)) {
3737
return [
38-
sprintf(
39-
'%s',
40-
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_CATEGORY_LAYOUT_HANDLE)
41-
)
38+
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_CATEGORY_LAYOUT_HANDLE)
4239
];
4340
}
4441
return [];
@@ -47,13 +44,12 @@ public function getTags($object)
4744
/**
4845
* Check if existing category page layout change
4946
*
50-
* @param AbstractModel $object
47+
* @param Category $object
5148
* @return bool
5249
*/
53-
private function isExistingCategoryLayoutChange(AbstractModel $object): bool
50+
private function isExistingCategoryLayoutChange(Category $object): bool
5451
{
55-
return $object instanceof Category &&
56-
!$object->isObjectNew() && $this->isObjectChanged($object);
52+
return !$object->isObjectNew() && $this->isObjectChanged($object);
5753
}
5854

5955
/**

app/code/Magento/Catalog/Model/Product/LayoutCacheTagResolver.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public function getTags($object)
3535
{
3636
if ($this->isExistingProductLayoutChange($object)) {
3737
return [
38-
sprintf(
39-
'%s',
40-
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_PRODUCT_LAYOUT_HANDLE)
41-
)
38+
str_replace('{{ID}}', (string) $object->getId(), Instance::SINGLE_PRODUCT_LAYOUT_HANDLE)
4239
];
4340
}
4441
return [];
@@ -47,13 +44,12 @@ public function getTags($object)
4744
/**
4845
* Check if existing Product page layout change
4946
*
50-
* @param AbstractModel $object
47+
* @param Product $object
5148
* @return bool
5249
*/
53-
private function isExistingProductLayoutChange(AbstractModel $object): bool
50+
private function isExistingProductLayoutChange(Product $object): bool
5451
{
55-
return $object instanceof Product &&
56-
!$object->isObjectNew() && $this->isObjectChanged($object);
52+
return !$object->isObjectNew() && $this->isObjectChanged($object);
5753
}
5854

5955
/**

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,9 @@
13591359
</argument>
13601360
</arguments>
13611361
</type>
1362-
<type name="Magento\Theme\Model\LayoutCacheTagResolverFactory">
1362+
<virtualType name="LayoutCacheTagResolverFactory" type="Magento\Framework\App\Cache\Tag\Strategy\Factory">
13631363
<arguments>
1364-
<argument name="cacheTagsResolvers" xsi:type="array">
1364+
<argument name="customStrategies" xsi:type="array">
13651365
<item name="Magento\Catalog\Model\Product" xsi:type="object">
13661366
Magento\Catalog\Model\Product\LayoutCacheTagResolver
13671367
</item>
@@ -1370,5 +1370,5 @@
13701370
</item>
13711371
</argument>
13721372
</arguments>
1373-
</type>
1373+
</virtualType>
13741374
</config>

app/code/Magento/Cms/Model/Page/LayoutCacheTagResolver.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use Magento\Cms\Model\Page;
2222
use Magento\Framework\App\Cache\Tag\StrategyInterface;
23-
use Magento\Framework\Model\AbstractModel;
2423

2524
/**
2625
* Get additional layout cache tag for CMS layout.
@@ -34,11 +33,8 @@ public function getTags($object)
3433
{
3534
if ($this->isExistingPageLayoutChange($object)) {
3635
return [
37-
sprintf(
38-
'%s_%s',
39-
'CMS_PAGE_VIEW_ID',
40-
str_replace('-', '_', strtoupper($object->getIdentifier()))
41-
)
36+
'CMS_PAGE_VIEW_ID_'.
37+
str_replace('-', '_', strtoupper($object->getIdentifier()))
4238
];
4339
}
4440
return [];
@@ -47,12 +43,12 @@ public function getTags($object)
4743
/**
4844
* Check if existing CMS page layout change
4945
*
50-
* @param AbstractModel $object
46+
* @param Page $object
5147
* @return bool
5248
*/
53-
private function isExistingPageLayoutChange(AbstractModel $object): bool
49+
private function isExistingPageLayoutChange(Page $object): bool
5450
{
55-
return $object instanceof Page && !$object->isObjectNew() &&
51+
return !$object->isObjectNew() &&
5652
$object->dataHasChangedFor(Page::PAGE_LAYOUT);
5753
}
5854
}

app/code/Magento/Cms/etc/di.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@
316316
</argument>
317317
</arguments>
318318
</virtualType>
319-
<type name="Magento\Theme\Model\LayoutCacheTagResolverFactory">
319+
<virtualType name="LayoutCacheTagResolverFactory" type="Magento\Framework\App\Cache\Tag\Strategy\Factory">
320320
<arguments>
321-
<argument name="cacheTagsResolvers" xsi:type="array">
321+
<argument name="customStrategies" xsi:type="array">
322322
<item name="Magento\Cms\Model\Page" xsi:type="object">
323323
Magento\Cms\Model\Page\LayoutCacheTagResolver
324324
</item>
325325
</argument>
326326
</arguments>
327-
</type>
327+
</virtualType>
328328
</config>

app/code/Magento/Theme/Model/LayoutCacheTagResolverFactory.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/code/Magento/Theme/Observer/InvalidateLayoutCacheObserver.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Magento\Framework\App\Cache\StateInterface as CacheState;
2323
use Magento\Framework\Event\Observer;
2424
use Magento\Framework\Event\ObserverInterface;
25-
use Magento\Theme\Model\LayoutCacheTagResolverFactory;
25+
use Magento\Framework\App\Cache\Tag\Strategy\Factory;
2626

2727
/**
2828
* Invalidates layout cache.
@@ -40,23 +40,25 @@ class InvalidateLayoutCacheObserver implements ObserverInterface
4040
private $cacheState;
4141

4242
/**
43-
* @var LayoutCacheTagResolverFactory
43+
* Tag strategies factory
44+
*
45+
* @var Factory
4446
*/
45-
private $layoutCacheTagResolver;
47+
private $strategyFactory;
4648

4749
/**
4850
* @param LayoutCache $layoutCache
4951
* @param CacheState $cacheState
50-
* @param LayoutCacheTagResolverFactory $layoutCacheTagResolver
52+
* @param Factory $factory
5153
*/
5254
public function __construct(
5355
LayoutCache $layoutCache,
5456
CacheState $cacheState,
55-
LayoutCacheTagResolverFactory $layoutCacheTagResolver
57+
Factory $factory
5658
) {
5759
$this->layoutCache = $layoutCache;
5860
$this->cacheState = $cacheState;
59-
$this->layoutCacheTagResolver = $layoutCacheTagResolver;
61+
$this->strategyFactory = $factory;
6062
}
6163

6264
/**
@@ -69,17 +71,16 @@ public function __construct(
6971
public function execute(Observer $observer): void
7072
{
7173
$object = $observer->getEvent()->getObject();
72-
$tagResolver = $this->layoutCacheTagResolver->getResolver($object);
7374

74-
if (!$tagResolver || !is_object($object)) {
75+
if (!is_object($object)) {
7576
return;
7677
}
7778

7879
if (!$this->cacheState->isEnabled(LayoutCache::TYPE_IDENTIFIER)) {
7980
return;
8081
}
8182

82-
$tags = $tagResolver->getTags($object);
83+
$tags = $this->strategyFactory->getStrategy($object)->getTags($object);
8384

8485
if (!empty($tags)) {
8586
$this->layoutCache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);

app/code/Magento/Theme/etc/di.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,9 @@
334334
<type name="Magento\Config\Console\Command\LocaleEmulator">
335335
<plugin name="themeForLocaleEmulator" type="Magento\Theme\Plugin\LocaleEmulator"/>
336336
</type>
337-
337+
<type name="Magento\Theme\Observer\InvalidateLayoutCacheObserver">
338+
<arguments>
339+
<argument name="strategyFactory" xsi:type="object">LayoutCacheTagResolverFactory</argument>
340+
</arguments>
341+
</type>
338342
</config>

0 commit comments

Comments
 (0)