Skip to content

Commit 46db9d8

Browse files
author
Alexander Paliarush
committed
MAGETWO-50551: When saving product or category cache cleared by general tag
1 parent aad945c commit 46db9d8

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
4848
$tags = [];
4949
$pattern = "((^|,)%s(,|$))";
5050
foreach ($object->getIdentities() as $tag) {
51-
$tags[] = sprintf($pattern, preg_replace("~_\\d+$~", '', $tag));
5251
$tags[] = sprintf($pattern, $tag);
5352
}
5453
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
307307
*/
308308
protected $_productIdCached;
309309

310+
/**
311+
* @var \Magento\Framework\App\State
312+
*/
313+
private $appState;
314+
310315
/**
311316
* List of attributes in ProductInterface
312317
* @var array
@@ -2263,6 +2268,9 @@ public function getIdentities()
22632268
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22642269
}
22652270
}
2271+
if ($this->getAppState()->getAreaCode() === 'frontend') {
2272+
$identities[] = self::CACHE_TAG;
2273+
}
22662274
return array_unique($identities);
22672275
}
22682276

@@ -2548,4 +2556,31 @@ public function setId($value)
25482556
{
25492557
return $this->setData('entity_id', $value);
25502558
}
2559+
2560+
/**
2561+
* Get application state
2562+
*
2563+
* @return \Magento\Framework\App\State
2564+
*/
2565+
private function getAppState()
2566+
{
2567+
if (!$this->appState instanceof \Magento\Framework\App\State) {
2568+
return \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\State');
2569+
} else {
2570+
return $this->appState;
2571+
}
2572+
}
2573+
2574+
/**
2575+
* Set application state
2576+
*
2577+
* @deprecated
2578+
* @param \Magento\Framework\App\State $appState
2579+
* @return $this
2580+
*/
2581+
public function setAppState(\Magento\Framework\App\State $appState)
2582+
{
2583+
$this->appState = $appState;
2584+
return $this;
2585+
}
25512586
}

app/code/Magento/PageCache/Observer/FlushCacheByTags.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5353
$object = $observer->getEvent()->getObject();
5454
if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
5555
$tags = $object->getIdentities();
56-
foreach ($tags as $tag) {
57-
$tags[] = preg_replace("~_\\d+$~", '', $tag);
58-
}
5956
if (!empty($tags)) {
6057
$this->getCache()->clean(\Zend_Cache::CLEANING_MODE_ALL, array_unique($tags));
6158
}

0 commit comments

Comments
 (0)