Skip to content

Commit ce97f26

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-71576: [Backport] - Cache invalidation after saving catalog - RIATCS-340 - for 2.1
1 parent db627ed commit ce97f26

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Catalog\Model;
77

88
use Magento\Framework\Api\AttributeValueFactory;
9-
use Magento\Framework\DataObject\IdentityInterface;
109

1110
/**
1211
* Abstract model for catalog entities

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Configurable extends AbstractType
186186
private $salableProcessor;
187187

188188
/**
189-
* Cache attributes of products without and ID here.
189+
* Cache attributes of products without IDs here.
190190
*
191191
* @var ProductTypeConfigurable\Attribute\Collection[] Where keys are
192192
* objects' hashes and value are attributes.
@@ -480,42 +480,44 @@ private function generateConfigurableAttributesCacheId(
480480
private function findCachedConfigurableAttributes(
481481
Product $product
482482
) {
483+
//Trying to load attributes from cache.
483484
try {
484-
//Trying to load attributes from cache.
485485
$cacheId = $this->generateConfigurableAttributesCacheId($product);
486+
} catch (\Exception $exception) {
487+
$cacheId = null;
488+
}
489+
if ($cacheId) {
486490
$configurableAttributes = $this->getCache()->load($cacheId);
487491
$configurableAttributes
488492
= $this->hasCacheData($configurableAttributes);
489-
if (!$configurableAttributes) {
490-
throw new \RuntimeException();
493+
if ($configurableAttributes) {
494+
return $configurableAttributes;
491495
}
496+
}
492497

493-
return $configurableAttributes;
494-
} catch (\Exception $exception) {
495-
//Failed, trying local cache.
496-
$productHashId = spl_object_hash($product);
497-
if (
498+
//Failed, trying local cache.
499+
$productHashId = spl_object_hash($product);
500+
if (
498501
array_key_exists(
499502
$productHashId,
500503
$this->configurableAttributesLocalCache
501504
)
502-
) {
503-
$configurableAttributes
504-
= $this->configurableAttributesLocalCache[$productHashId];
505-
//If product has ID then caching attributes for further use.
506-
$metadata = $this->getMetadataPool()
507-
->getMetadata(ProductInterface::class);
508-
/** @var string|null $productId */
509-
$productId = $product->getData($metadata->getLinkField());
510-
if ($productId) {
511-
$this->cacheConfigurableAttributes(
512-
$product,
513-
$configurableAttributes
514-
);
515-
}
516-
517-
return $configurableAttributes;
505+
) {
506+
$configurableAttributes
507+
= $this->configurableAttributesLocalCache[$productHashId];
508+
//If product has ID then caching attributes for further use.
509+
$metadata = $this->getMetadataPool()
510+
->getMetadata(ProductInterface::class);
511+
/** @var string|null $productId */
512+
$productId = $product->getData($metadata->getLinkField());
513+
if ($productId) {
514+
$this->cacheConfigurableAttributes(
515+
$product,
516+
$configurableAttributes
517+
);
518518
}
519+
520+
return $configurableAttributes;
519521
}
520522

521523
throw new \RuntimeException(

0 commit comments

Comments
 (0)