Skip to content

Commit 6676522

Browse files
committed
added cache for graphql
1 parent 02c8ccd commit 6676522

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_MarketplaceGraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
namespace Lof\MarketplaceGraphQl\Model\Resolver\SellerById;
23+
24+
25+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
26+
27+
class Identity implements IdentityInterface
28+
{
29+
30+
private $cacheTag = \Magento\Framework\App\Config::CACHE_TAG;
31+
32+
/**
33+
* @param array $resolvedData
34+
* @return string[]
35+
*/
36+
public function getIdentities(array $resolvedData)
37+
{
38+
$ids = empty($resolvedData['seller_id']) ?
39+
[] : [$this->cacheTag, sprintf('%s_%s', $this->cacheTag, $resolvedData['seller_id'])];
40+
41+
return $ids;
42+
}
43+
}
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Landofcoder
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Landofcoder.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://landofcoder.com/terms
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Landofcoder
17+
* @package Lof_MarketplaceGraphQl
18+
* @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/)
19+
* @license https://landofcoder.com/terms
20+
*/
21+
22+
namespace Lof\MarketplaceGraphQl\Model\Resolver\SellerByProduct;
23+
24+
25+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
26+
27+
class Identity implements IdentityInterface
28+
{
29+
30+
private $cacheTag = \Magento\Framework\App\Config::CACHE_TAG;
31+
32+
/**
33+
* @param array $resolvedData
34+
* @return string[]
35+
*/
36+
public function getIdentities(array $resolvedData)
37+
{
38+
$ids = empty($resolvedData['product_sku']) ?
39+
[] : [$this->cacheTag, sprintf('%s_%s', $this->cacheTag, $resolvedData['product_sku'])];
40+
41+
return $ids;
42+
}
43+
}
44+

etc/schema.graphqls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ type StoreConfig {
5050
type Query {
5151
lofSellerById(
5252
seller_id: Int! @doc(description: "Seller id")
53-
): Seller @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerById") @doc(description: "Get Seller by ID")
53+
): Seller @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerById") @doc(description: "Get Seller by ID") @cache( cacheIdentity: "Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerById\\Identity")
5454

5555
lofSellerByProduct(
5656
product_sku: String! @doc(description: "Product SKU")
57-
): Seller @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerByProduct") @doc(description: "Get Seller by ID")
57+
): Seller @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerByProduct") @doc(description: "Get Seller by ID") @cache( cacheIdentity: "Lof\\MarketplaceGraphQl\\Model\\Resolver\\SellerByProduct\\Identity")
5858

5959
lofProductBySellerId(
6060
seller_id: Int! @doc(description: "Seller id")
@@ -78,7 +78,7 @@ type Query {
7878
pageSize: Int = 5 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
7979
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."),
8080
sort: SellerSortInput @doc(description: "Specifies which attributes to sort on, and whether to return the results in ascending or descending order.")
81-
):Sellers @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\Sellers") @doc(description: "The seller query searches for sellers that match the criteria specified in the search and filter attributes")
81+
):Sellers @resolver(class: "\\Lof\\MarketplaceGraphQl\\Model\\Resolver\\Sellers") @doc(description: "The seller query searches for sellers that match the criteria specified in the search and filter attributes") @cache( cacheIdentity: "Lof\\MarketplaceGraphQl\\Model\\Resolver\\Sellers\\Identity")
8282
}
8383

8484
type Mutation {

0 commit comments

Comments
 (0)