Skip to content

Commit 4c3bac4

Browse files
committed
B2B-2258: Add caching capability to the storeConfig GraphQl query
1 parent 81706d5 commit 4c3bac4

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\StoreGraphQl\Model\Cache\Tag\Strategy;
9+
10+
use Magento\Config\App\Config\Type\System;
11+
use Magento\Framework\App\Cache\Tag\StrategyInterface;
12+
use Magento\Framework\App\Config\ValueInterface;
13+
14+
/**
15+
* Produce cache tags for store config.
16+
*/
17+
class StoreConfig implements StrategyInterface
18+
{
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function getTags($object): array
23+
{
24+
if (!is_object($object)) {
25+
throw new \InvalidArgumentException('Provided argument is not an object');
26+
}
27+
28+
if ($object instanceof ValueInterface && $object->isValueChanged()) {
29+
return [System::CACHE_TAG];
30+
}
31+
32+
return [];
33+
}
34+
}

app/code/Magento/StoreGraphQl/Model/Resolver/Store/Identity.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77

88
namespace Magento\StoreGraphQl\Model\Resolver\Store;
99

10+
use Magento\Config\App\Config\Type\System;
1011
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
11-
use Magento\Framework\App\Config;
1212

1313
class Identity implements IdentityInterface
1414
{
1515
/**
1616
* @var string
1717
*/
18-
private $cacheTag = Config::CACHE_TAG;
18+
private $cacheTag = System::CACHE_TAG;
1919

2020
/**
2121
* @inheritDoc
2222
*/
2323
public function getIdentities(array $resolvedData): array
2424
{
25-
$data["id"] = empty($resolvedData) ? [] : $resolvedData["id"];
2625
$ids = empty($resolvedData) ?
27-
[] : array_merge([$this->cacheTag], array_map(function ($key) {
28-
return sprintf('%s_%s', $this->cacheTag, $key);
29-
}, $data));
26+
[] : [$this->cacheTag];
3027
return $ids;
3128
}
3229
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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\Framework\App\Cache\Tag\Strategy\Factory">
10+
<arguments>
11+
<argument name="customStrategies" xsi:type="array">
12+
<item name="Magento\Framework\App\Config\ValueInterface" xsi:type="object">Magento\StoreGraphQl\Model\Cache\Tag\Strategy\StoreConfig</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
</config>

0 commit comments

Comments
 (0)