{"id":382140,"date":"2023-05-18T05:17:35","date_gmt":"2023-05-18T05:17:35","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=382140"},"modified":"2025-12-16T09:46:43","modified_gmt":"2025-12-16T09:46:43","slug":"graphql-caching","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/graphql-caching\/","title":{"rendered":"Graphql Caching In Magento 2"},"content":{"rendered":"\n<p>Here, we will learn about <em>GraphQL Caching in Magento 2<\/em> and explore how to implement <em>GraphQL Caching in Magento 2<\/em> effectively.<\/p>\n\n\n\n<p>Caching speeds up responses and reduces server load by avoiding repeated database queries and code execution. You can cache HTTP GET requests, but the system does not cache HTTP POST requests.<\/p>\n\n\n\n<p>The definitions for some queries include cache tags because caching uses these tags to keep track of cached content. <\/p>\n\n\n\n<p>GraphQL allows you to make multiple queries in a single call. If you specify any uncached query, the system bypasses the cache for all queries in the call.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s create a Custom module to perform GraphQL caching.<\/h2>\n\n\n\n<p>First, we will create a registration.php file inside the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    &quot;Webkul_CustomGraphQl&quot;,\n    __DIR__\n);<\/pre>\n\n\n\n<p>Create the module.xml file in the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/etc\/module.xml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module\/etc\/module.xsd&quot;&gt;\n    &lt;module name=&quot;Webkul_CustomGraphQl&quot; setup_version=&quot;1.0.0&quot;&gt;        \n        &lt;sequence&gt;\n                &lt;module name=&quot;Magento_Catalog&quot;\/&gt;\n                &lt;module name=&quot;Magento_GraphQl&quot;\/&gt;\n        &lt;\/sequence&gt;\n    &lt;\/module&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p>Now we will create a <strong>schema.graphqls<\/strong> file in the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/etc<\/strong><\/p>\n\n\n\n<p>This file contains the schema for your GraphQL query, like the resolver class and type.<\/p>\n\n\n\n<p>The @doc directive defines that if we need to add some description to our query.<\/p>\n\n\n\n<p>A resolver processes GraphQL requests by constructing queries, fetching data, and performing any necessary calculations.<\/p>\n\n\n\n<p> Resolver transforms the fetched and calculated data into a GraphQL array format and returns the results wrapped by a callable function<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">@cache Directive<\/h2>\n\n\n\n<p>The&nbsp;<code>@cache<\/code>&nbsp;directive defines whether the results of certain queries can be cached.<\/p>\n\n\n\n<p>The&nbsp;<code><strong>cacheIdentity<\/strong><\/code>&nbsp;value points to the&nbsp;class&nbsp;responsible for retrieving cache tags.<\/p>\n\n\n\n<p>Additionally, a query without a&nbsp;<code><strong>cacheIdentity<\/strong><\/code>&nbsp;will not be cached.<\/p>\n\n\n\n<p>Use the <strong>@cache(cacheable: false)<\/strong> directive to disable caching for queries defined in other modules, when a <code><strong>cacheIdentity<\/strong><\/code> class is set. This is useful when the system should not reuse cached results.<\/p>\n\n\n\n<p>Using <strong>@cache(cacheable: true\/false)<\/strong> has no effect if no <strong><code><strong>cacheIdentity<\/strong><\/code><\/strong> is set\u2014the query will not be cached. To prevent caching, simply omit the <strong>@cache<\/strong> directive.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">type Query {\n    categoryProductlist (\n        categoryId: Int\n        pageSize: Int\n        currentPage: Int\n    ) : CategoryProductList @doc(description: &quot;Get CategoryProductList&quot;) @resolver(class: &quot;Webkul\\\\CustomGraphQl\\\\Model\\\\Resolver\\\\ProductsCollection&quot;) @cache(cacheIdentity: &quot;Webkul\\\\CustomGraphQl\\\\Model\\\\Resolver\\\\Block\\\\CustomCategoryIdentity&quot;)                    \n}\n\ntype CategoryProductList {\n    totalCount: Int\n    category_product_list: &#091;CategoryProductListItems]\n}\n\ntype CategoryProductListItems {\n    entity_id: Int\n    type_id: String\n    sku: String\n    name: String\n    image: String\n    status: String\n    visibility: String\n    price: String\n}<\/pre>\n\n\n\n<p>Now we will create the resolver ProductsCollection.php in the path below because this class contains all the logic.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/Model\/Resolver<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\ndeclare(strict_types=1);\n\nnamespace Webkul\\CustomGraphQl\\Model\\Resolver;\n\nuse Magento\\Framework\\GraphQl\\Exception\\GraphQlInputException;\nuse Magento\\Framework\\GraphQl\\Config\\Element\\Field;\nuse Magento\\Framework\\GraphQl\\Exception\\GraphQlNoSuchEntityException;\nuse Magento\\Framework\\GraphQl\\Schema\\Type\\ResolveInfo;\nuse Magento\\Framework\\GraphQl\\Query\\ResolverInterface;\n\nclass ProductsCollection implements ResolverInterface\n{\n   \/**\n    * @var \\Magento\\Catalog\\Model\\CategoryFactory\n    *\/\n   protected $categoryFactory;\n \n   \/**\n    * @inheritdoc\n    *\/\n   public function __construct(\n        \\Magento\\Catalog\\Model\\CategoryFactory $categoryFactory,\n    ) {\n        $this-&gt;categoryFactory = $categoryFactory;\n    }\n\n      \/**\n     * @return array\n     * @throws GraphQlNoSuchEntityException\n     *\/\n   public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null)\n    {\n        try {\n            $category = $this-&gt;categoryFactory-&gt;create();\n            $category-&gt;load($args&#091;&#039;categoryId&#039;]);\n            $products = $category-&gt;getProductCollection()-&gt;distinct(true);\n            $products-&gt;addAttributeToSelect(&#039;*&#039;);\n            $productCount = $products-&gt;getSize();\n            $products-&gt;setPageSize($args&#091;&#039;pageSize&#039;] ?? 10);\n            $products-&gt;setCurPage($args&#091;&#039;currentPage&#039;] ?? 1);\n            $productList = &#091;];\n            foreach ($products as $product) {\n                $eachProduct = &#091;];\n                $eachProduct = $product-&gt;toArray();\n                $productList&#091;] = $eachProduct;\n            }\n            \n            $productRecord&#091;&#039;totalCount&#039;] = $productCount;\n            $productRecord&#091;&#039;category_product_list&#039;] = $productList;\n           \n        } catch (NoSuchEntityException $e) {\n            throw new GraphQlNoSuchEntityException(__($e-&gt;getMessage()), $e);\n        }\n        return $productRecord;\n    }\n\n        \n}<\/pre>\n\n\n\n<p>Now we will create an Identity class for caching our query, named <code>CustomCategoryIdentity.php<\/code> in the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/Model\/Resolver\/Block<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\ndeclare(strict_types=1);\n\nnamespace Webkul\\CustomGraphQl\\Model\\Resolver\\Block;\n\nuse Magento\\Framework\\GraphQl\\Query\\Resolver\\IdentityInterface;\n\n\/**\n * Get identities from resolved data\n *\/\nclass CustomCategoryIdentity implements IdentityInterface\n{\n    private $cacheTag = &#039;wk_category_products_custom&#039;;\n\n    \/**\n     * Get identity tags from resolved data\n     *\n     * @param array $resolvedData\n     * @return string&#091;]\n     *\/\n    public function getIdentities(array $resolvedData): array\n    {\n        $ids = &#091;];\n        $items = $resolvedData&#091;&#039;category_product_list&#039;] ?? &#091;];\n        foreach ($items as $item) {\n            $ids&#091;] = sprintf(&#039;%s_%s&#039;, $this-&gt;cacheTag, $item&#091;&#039;entity_id&#039;]);\n        }\n        if (!empty($ids)) {\n            $ids&#091;] = $this-&gt;cacheTag;\n        }\n        return $ids;\n    }\n}<\/pre>\n\n\n\n<p>After creating all files, register the module by running <code><em>bin\/magento setup:upgrade<\/em><\/code>, then run <code><em>bin\/magento setup:di:compile<\/em><\/code> and clean the cache.<\/p>\n\n\n\n<p>We will now test our GraphQL query.<\/p>\n\n\n\n<p>Here\u2019s an example of a request.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">{\n  categoryProductlist(categoryId: 2, pageSize: 20, currentPage: 1) {\n    totalCount\n    category_product_list {\n      entity_id\n      type_id\n      sku\n      name\n      image\n      status\n      visibility\n      price\n    }\n  }\n}<\/pre>\n\n\n\n<p>We will get a response like below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1034\" height=\"601\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\" alt=\"Selection_004\" class=\"wp-image-382163\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png 1034w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004-300x174.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004-250x145.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004-768x446.png 768w\" sizes=\"(max-width: 1034px) 100vw, 1034px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Check headers for cached params.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1033\" height=\"592\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_005.png\" alt=\"Selection_005\" class=\"wp-image-382164\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_005.png 1033w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_005-300x172.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_005-250x143.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_005-768x440.png 768w\" sizes=\"(max-width: 1033px) 100vw, 1033px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>The X-Magento-Cache-Debug header shows MISS, which means the system did not cache the query.<\/p>\n\n\n\n<p>Create a GET request with a GraphQL query because the system does not cache POST requests.<\/p>\n\n\n\n<p>Request Type =&gt; GET<\/p>\n\n\n\n<p><strong>{{base_url}}\/graphql?query={categoryProductlist(categoryId: 2, pageSize: 20, currentPage: 1) {totalCount category_product_list {entity_id type_id sku name image status visibility price } } }<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1046\" height=\"616\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_006.png\" alt=\"Selection_006\" class=\"wp-image-382170\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_006.png 1046w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_006-300x177.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_006-250x147.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_006-768x452.png 768w\" sizes=\"(max-width: 1046px) 100vw, 1046px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Above headers show <strong>X-Magento-Cache-Debug : HIT<\/strong> <\/p>\n\n\n\n<p>Now, the system caches our query.<\/p>\n\n\n\n<p>In this way, we can achieve GraphQL caching<\/p>\n\n\n\n<p>Create an observer that invalidates cache tags whenever the admin saves a product.<\/p>\n\n\n\n<p>Create a file <strong>events.xml<\/strong>  in the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/etc\/adminhtml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Event\/etc\/events.xsd&quot;&gt;\n    &lt;event name=&quot;catalog_product_save_after&quot;&gt;\n        &lt;observer name=&quot;clear_cache_tags_custom&quot; instance=&quot;Webkul\\CustomGraphQl\\Observer\\Productsaveafter&quot; \/&gt;\n    &lt;\/event&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p>Now we will create an observer file named <strong>Productsaveafter.php<\/strong> in the path below.<\/p>\n\n\n\n<p><strong>app\/code\/Webkul\/CustomGraphQl\/Observer<\/strong><\/p>\n\n\n\n<p>Add the code below to the file that we have just created.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\CustomGraphQl\\Observer;\n\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Zend_Cache;\nuse Magento\\PageCache\\Model\\Cache\\Type;\n\nclass Productsaveafter implements ObserverInterface\n{ \n    \/**\n     * @var Type\n     *\/\n    private $fullPageCache;\n\n    \/**\n     * @param Type $fullPageCache\n     *\/\n    public function __construct(\n        Type $fullPageCache\n    ) {\n        $this-&gt;fullPageCache = $fullPageCache;\n    }\n\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        $_product = $observer-&gt;getProduct();\n        $productId = $_product-&gt;getId();\n        $tags = &#091;&#039;wk_category_products_custom_&#039;.$productId];\n        if (!empty($tags)) {\n            $this-&gt;fullPageCache-&gt;clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_unique($tags));\n        }\n    }   \n}<\/pre>\n\n\n\n<p>In this way, we can invalidate custom cache tags for our GraphQL query.<\/p>\n\n\n\n<p>Check for other blogs as well:<a href=\"https:\/\/developer.adobe.com\/commerce\/webapi\/graphql\/usage\/\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a> <a href=\"https:\/\/webkul.com\/blog\/graphql-mutation-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/webkul.com\/blog\/graphql-mutation-2\/<\/a><\/p>\n\n\n\n<p>For technical assistance, please get in touch with us via email at <a href=\"mailto:support@webkul.com\" target=\"_blank\" rel=\"noreferrer noopener\">support@webkul.com<\/a><\/p>\n\n\n\n<p>Take your Magento 2 store to the next level\u2014browse our <a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Magento 2 plugins<\/a> page for smart enhancements.<\/p>\n\n\n\n<p>Need something custom? <a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">Hire Magento 2<\/a> developers to build solutions tailored to your needs.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here, we will learn about GraphQL Caching in Magento 2 and explore how to implement GraphQL Caching in Magento 2 effectively. Caching speeds up responses and reduces server load by avoiding repeated database queries and code execution. You can cache HTTP GET requests, but the system does not cache HTTP POST requests. The definitions for <a href=\"https:\/\/webkul.com\/blog\/graphql-caching\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":605,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-382140","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Graphql Caching in Magento 2<\/title>\n<meta name=\"description\" content=\"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/graphql-caching\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Graphql Caching in Magento 2\" \/>\n<meta property=\"og:description\" content=\"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/graphql-caching\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-18T05:17:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-16T09:46:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\" \/>\n<meta name=\"author\" content=\"Atif Yaqoob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Atif Yaqoob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/\"},\"author\":{\"name\":\"Atif Yaqoob\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa\"},\"headline\":\"Graphql Caching In Magento 2\",\"datePublished\":\"2023-05-18T05:17:35+00:00\",\"dateModified\":\"2025-12-16T09:46:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/\"},\"wordCount\":615,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/graphql-caching\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/\",\"url\":\"https:\/\/webkul.com\/blog\/graphql-caching\/\",\"name\":\"Graphql Caching in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\",\"datePublished\":\"2023-05-18T05:17:35+00:00\",\"dateModified\":\"2025-12-16T09:46:43+00:00\",\"description\":\"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/graphql-caching\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png\",\"width\":1034,\"height\":601,\"caption\":\"Selection_004\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/graphql-caching\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Graphql Caching In Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa\",\"name\":\"Atif Yaqoob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Atif Yaqoob\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/atif-yakoob869\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Graphql Caching in Magento 2","description":"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/graphql-caching\/","og_locale":"en_US","og_type":"article","og_title":"Graphql Caching in Magento 2","og_description":"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.","og_url":"https:\/\/webkul.com\/blog\/graphql-caching\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-05-18T05:17:35+00:00","article_modified_time":"2025-12-16T09:46:43+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png","type":"","width":"","height":""}],"author":"Atif Yaqoob","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Atif Yaqoob","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/"},"author":{"name":"Atif Yaqoob","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa"},"headline":"Graphql Caching In Magento 2","datePublished":"2023-05-18T05:17:35+00:00","dateModified":"2025-12-16T09:46:43+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/"},"wordCount":615,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/graphql-caching\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/graphql-caching\/","url":"https:\/\/webkul.com\/blog\/graphql-caching\/","name":"Graphql Caching in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png","datePublished":"2023-05-18T05:17:35+00:00","dateModified":"2025-12-16T09:46:43+00:00","description":"GraphQL Caching in Magento 2 improves response time and reduces the server load. Without caching, each page might need to run blocks of code.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/graphql-caching\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/05\/Selection_004.png","width":1034,"height":601,"caption":"Selection_004"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/graphql-caching\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Graphql Caching In Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/2273bf3f70f0107d46749e115bf818fa","name":"Atif Yaqoob","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5ed5b0a496b935107cbfc11af454d90dc3e6458b661598c2027cfcfbbf88a915?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Atif Yaqoob"},"url":"https:\/\/webkul.com\/blog\/author\/atif-yakoob869\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/605"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=382140"}],"version-history":[{"count":94,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382140\/revisions"}],"predecessor-version":[{"id":517407,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/382140\/revisions\/517407"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=382140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=382140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=382140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}