1616use Magento \ConfigurableProduct \Model \Product \Type \Configurable ;
1717use Magento \Framework \Api \FilterBuilder ;
1818use Magento \Framework \Api \SearchCriteriaBuilder ;
19+ use Magento \Framework \App \CacheInterface ;
1920use Magento \Framework \App \ObjectManager ;
2021use Magento \Framework \DataObject ;
22+ use Magento \Framework \Event \Manager as EventManager ;
2123use Magento \Framework \Indexer \ActionInterface ;
2224use Magento \Framework \Indexer \CacheContext ;
23- use Magento \Indexer \Model \Indexer \DeferredCacheCleaner ;
2425
2526/**
2627 * Plugin product resource model
@@ -55,14 +56,19 @@ class Product
5556 private $ filterBuilder ;
5657
5758 /**
58- * @var DeferredCacheCleaner
59+ * @var CacheContext
5960 */
60- private $ cacheCleaner ;
61+ private $ cacheContext ;
6162
6263 /**
63- * @var CacheContext
64+ * @var EventManager
6465 */
65- private $ cacheContext ;
66+ private $ eventManager ;
67+
68+ /**
69+ * @var CacheInterface
70+ */
71+ private $ appCache ;
6672
6773 /**
6874 * Initialize Product dependencies.
@@ -72,17 +78,19 @@ class Product
7278 * @param ProductAttributeRepositoryInterface|null $productAttributeRepository
7379 * @param SearchCriteriaBuilder|null $searchCriteriaBuilder
7480 * @param FilterBuilder|null $filterBuilder
75- * @param DeferredCacheCleaner|null $cacheCleaner
7681 * @param CacheContext|null $cacheContext
82+ * @param EventManager|null $eventManager
83+ * @param CacheInterface|null $appCache
7784 */
7885 public function __construct (
7986 Configurable $ configurable ,
8087 ActionInterface $ productIndexer ,
8188 ProductAttributeRepositoryInterface $ productAttributeRepository = null ,
8289 ?SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
8390 ?FilterBuilder $ filterBuilder = null ,
84- ?DeferredCacheCleaner $ cacheCleaner = null ,
85- ?CacheContext $ cacheContext = null
91+ ?CacheContext $ cacheContext = null ,
92+ ?EventManager $ eventManager = null ,
93+ ?CacheInterface $ appCache = null
8694 ) {
8795 $ this ->configurable = $ configurable ;
8896 $ this ->productIndexer = $ productIndexer ;
@@ -92,8 +100,9 @@ public function __construct(
92100 ->get (SearchCriteriaBuilder::class);
93101 $ this ->filterBuilder = $ filterBuilder ?: ObjectManager::getInstance ()
94102 ->get (FilterBuilder::class);
95- $ this ->cacheCleaner = $ cacheCleaner ?? ObjectManager::getInstance ()->get (DeferredCacheCleaner::class);
96103 $ this ->cacheContext = $ cacheContext ?? ObjectManager::getInstance ()->get (CacheContext::class);
104+ $ this ->eventManager = $ eventManager ?? ObjectManager::getInstance ()->get (EventManager::class);
105+ $ this ->appCache = $ appCache ?? ObjectManager::getInstance ()->get (CacheInterface::class);
97106 }
98107
99108 /**
@@ -133,9 +142,13 @@ public function afterSave(
133142 ): ProductResource {
134143 $ configurableProductIds = $ this ->configurable ->getParentIdsByChild ($ object ->getId ());
135144 if (count ($ configurableProductIds ) > 0 ) {
136- $ this ->cacheCleaner ->start ();
137145 $ this ->cacheContext ->registerEntities (ProductModel::CACHE_TAG , $ configurableProductIds );
138- $ this ->cacheCleaner ->flush ();
146+ $ this ->eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ->cacheContext ]);
147+ $ identities = $ this ->cacheContext ->getIdentities ();
148+ if (!empty ($ identities )) {
149+ $ this ->appCache ->clean ($ identities );
150+ $ this ->cacheContext ->flush ();
151+ }
139152 }
140153
141154 return $ result ;
0 commit comments