@@ -56,6 +56,11 @@ class UrlRewrite extends AbstractModel
56
56
*/
57
57
private $ eventManager ;
58
58
59
+ /**
60
+ * @var array
61
+ */
62
+ private $ entityToCacheTagMap ;
63
+
59
64
/**
60
65
* UrlRewrite constructor.
61
66
*
@@ -67,6 +72,7 @@ class UrlRewrite extends AbstractModel
67
72
* @param Json|null $serializer
68
73
* @param CacheContext|null $cacheContext
69
74
* @param EventManager|null $eventManager
75
+ * @param array $entityToCacheTagMap
70
76
*/
71
77
public function __construct (
72
78
Context $ context ,
@@ -76,12 +82,14 @@ public function __construct(
76
82
array $ data = [],
77
83
Json $ serializer = null ,
78
84
CacheContext $ cacheContext = null ,
79
- EventManager $ eventManager = null
85
+ EventManager $ eventManager = null ,
86
+ array $ entityToCacheTagMap = []
80
87
)
81
88
{
82
89
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Json::class);
83
90
$ this ->cacheContext = $ cacheContext ?: ObjectManager::getInstance ()->get (CacheContext::class);
84
91
$ this ->eventManager = $ eventManager ?: ObjectManager::getInstance ()->get (EventManager::class);
92
+ $ this ->entityToCacheTagMap = $ entityToCacheTagMap ;
85
93
parent ::__construct ($ context , $ registry , $ resource , $ resourceCollection , $ data );
86
94
}
87
95
@@ -130,14 +138,8 @@ public function setMetadata($metadata)
130
138
*/
131
139
private function cleanCacheForEntity ($ entityType , $ entityId )
132
140
{
133
- if ($ entityType !== Rewrite::ENTITY_TYPE_CUSTOM ) {
134
- $ map = [
135
- Rewrite::ENTITY_TYPE_PRODUCT => Product::CACHE_TAG ,
136
- Rewrite::ENTITY_TYPE_CATEGORY => Category::CACHE_TAG ,
137
- Rewrite::ENTITY_TYPE_CMS_PAGE => Page::CACHE_TAG
138
- ];
139
-
140
- $ cacheKey = $ map [$ entityType ];
141
+ if ($ entityType !== Rewrite::ENTITY_TYPE_CUSTOM && array_key_exists ($ entityType , $ this ->entityToCacheTagMap )) {
142
+ $ cacheKey = $ this ->entityToCacheTagMap [$ entityType ];
141
143
142
144
$ this ->cacheContext ->registerEntities ($ cacheKey , [$ entityId ]);
143
145
$ this ->eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ->cacheContext ]);
@@ -147,7 +149,7 @@ private function cleanCacheForEntity($entityType, $entityId)
147
149
public function afterDelete ()
148
150
{
149
151
$ this ->cleanCacheForEntity ($ this ->getEntityType (), $ this ->getEntityId ());
150
- return parent ::afterDelete (); // TODO: Change the autogenerated stub
152
+ return parent ::afterDelete ();
151
153
}
152
154
153
155
public function afterSave ()
0 commit comments