Skip to content

Commit b877306

Browse files
committed
B2B-2451: Implement GraphQL Resolver Cache for CMS Page Type
1 parent 385d791 commit b877306

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\GraphQlCache\Observer\InvalidateGraphQlResolverCacheObserver">
10+
<arguments>
11+
<argument name="invalidatableObjectTypes" xsi:type="array">
12+
<item name="Magento\Cms\Api\Data\PageInterface" xsi:type="string">
13+
Magento\Cms\Api\Data\PageInterface
14+
</item>
15+
</argument>
16+
</arguments>
17+
</type>
18+
</config>

app/code/Magento/GraphQlCache/Observer/InvalidateGraphQlResolverCacheObserver.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\GraphQlCache\Observer;
99

10-
use Magento\Cms\Api\Data\PageInterface;
1110
use Magento\Framework\App\Cache\StateInterface as CacheState;
1211
use Magento\Framework\App\Cache\Tag\Resolver as TagResolver;
1312
use Magento\Framework\Event\ObserverInterface;
@@ -31,19 +30,27 @@ class InvalidateGraphQlResolverCacheObserver implements ObserverInterface
3130
*/
3231
private $tagResolver;
3332

33+
/**
34+
* @var array
35+
*/
36+
private $invalidatableObjectTypes;
37+
3438
/**
3539
* @param GraphQlResolverCache $graphQlResolverCache
3640
* @param CacheState $cacheState
3741
* @param TagResolver $tagResolver
42+
* @param array $invalidatableObjectTypes
3843
*/
3944
public function __construct(
4045
GraphQlResolverCache $graphQlResolverCache,
4146
CacheState $cacheState,
42-
TagResolver $tagResolver
47+
TagResolver $tagResolver,
48+
array $invalidatableObjectTypes = []
4349
) {
4450
$this->graphQlResolverCache = $graphQlResolverCache;
4551
$this->cacheState = $cacheState;
4652
$this->tagResolver = $tagResolver;
53+
$this->invalidatableObjectTypes = $invalidatableObjectTypes;
4754
}
4855

4956
/**
@@ -61,11 +68,21 @@ public function execute(Observer $observer)
6168
return;
6269
}
6370

64-
if (!($object instanceof PageInterface)) {
71+
if (!$this->cacheState->isEnabled(GraphQlResolverCache::TYPE_IDENTIFIER)) {
6572
return;
6673
}
6774

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) {
6986
return;
7087
}
7188

0 commit comments

Comments
 (0)