Skip to content

Commit 2754427

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'remotes/api/MAGETWO-50551-Cache-Tags' into bug-fixes
2 parents bcf64cc + 631e111 commit 2754427

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ 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
}
54-
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
53+
if (!empty($tags)) {
54+
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
55+
}
5556
}
5657
}
5758
}

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

Lines changed: 24 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() === \Magento\Framework\App\Area::AREA_FRONTEND) {
2272+
$identities[] = self::CACHE_TAG;
2273+
}
22662274
return array_unique($identities);
22672275
}
22682276

@@ -2548,4 +2556,20 @@ public function setId($value)
25482556
{
25492557
return $this->setData('entity_id', $value);
25502558
}
2559+
2560+
/**
2561+
* Get application state
2562+
*
2563+
* @deprecated
2564+
* @return \Magento\Framework\App\State
2565+
*/
2566+
private function getAppState()
2567+
{
2568+
if (!$this->appState instanceof \Magento\Framework\App\State) {
2569+
$this->appState = \Magento\Framework\App\ObjectManager::getInstance()->get(
2570+
\Magento\Framework\App\State::class
2571+
);
2572+
}
2573+
return $this->appState;
2574+
}
25512575
}

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)