7
7
8
8
namespace Magento \GraphQlCache \Observer ;
9
9
10
- use Magento \Cms \Api \Data \PageInterface ;
11
10
use Magento \Framework \App \Cache \StateInterface as CacheState ;
12
11
use Magento \Framework \App \Cache \Tag \Resolver as TagResolver ;
13
12
use Magento \Framework \Event \ObserverInterface ;
@@ -31,19 +30,27 @@ class InvalidateGraphQlResolverCacheObserver implements ObserverInterface
31
30
*/
32
31
private $ tagResolver ;
33
32
33
+ /**
34
+ * @var array
35
+ */
36
+ private $ invalidatableObjectTypes ;
37
+
34
38
/**
35
39
* @param GraphQlResolverCache $graphQlResolverCache
36
40
* @param CacheState $cacheState
37
41
* @param TagResolver $tagResolver
42
+ * @param array $invalidatableObjectTypes
38
43
*/
39
44
public function __construct (
40
45
GraphQlResolverCache $ graphQlResolverCache ,
41
46
CacheState $ cacheState ,
42
- TagResolver $ tagResolver
47
+ TagResolver $ tagResolver ,
48
+ array $ invalidatableObjectTypes = []
43
49
) {
44
50
$ this ->graphQlResolverCache = $ graphQlResolverCache ;
45
51
$ this ->cacheState = $ cacheState ;
46
52
$ this ->tagResolver = $ tagResolver ;
53
+ $ this ->invalidatableObjectTypes = $ invalidatableObjectTypes ;
47
54
}
48
55
49
56
/**
@@ -61,11 +68,21 @@ public function execute(Observer $observer)
61
68
return ;
62
69
}
63
70
64
- if (!( $ object instanceof PageInterface )) {
71
+ if (!$ this -> cacheState -> isEnabled (GraphQlResolverCache:: TYPE_IDENTIFIER )) {
65
72
return ;
66
73
}
67
74
68
- if (!$ this ->cacheState ->isEnabled (GraphQlResolverCache::TYPE_IDENTIFIER )) {
75
+ $ isInvalidatable = false ;
76
+
77
+ foreach ($ this ->invalidatableObjectTypes as $ invalidatableObjectType ) {
78
+ $ isInvalidatable = $ object instanceof $ invalidatableObjectType ;
79
+
80
+ if ($ isInvalidatable ) {
81
+ break ;
82
+ }
83
+ }
84
+
85
+ if (!$ isInvalidatable ) {
69
86
return ;
70
87
}
71
88
0 commit comments