How to remove caching of GraphQL Persisted Query | Community
Skip to main content
Level 4
February 4, 2023
Solved

How to remove caching of GraphQL Persisted Query

  • February 4, 2023
  • 2 replies
  • 5378 views

I am using AEM as a Cloud Service and have created a component in which the data is rendered through the Content Fragments. To get the data stored in CFs, I have a GET request in my JS for the graphql persisted query. But the problem is the data is cached. No matter how many times I publish the CF, the data remains same and is updated after one day around or may take several days to be shown updated. This doc: https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/graphql/advanced-tutorial/graphql-persisted-queries.html?lang=en states that GET request in persisted queries are cached. But I don't want my request to be cached. How can I do that?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by nikita24tailor

Got the solution for this. Just added cache headers for the graphql in dispatcher and it worked.

2 replies

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 4, 2023

Hi @nikita24tailor ,

 

The same document talks about using cache-control - max-age feature to control caching. Have you tried that?

 

https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/graphql/advanced-tutorial/graphql-persisted-queries.html?lang=en

 

 

 

Thanks,

Ritesh Mittal

Level 4
February 4, 2023

I tried but didn't get the idea for the fields provided in the Headers. If you can tell me which fields do I need to set in the Headers to stop caching, that would be helpful.

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 4, 2023

Try setting cache control max-age as 0. This will make the TTL as zero and response will be invalidated. Also, make sure to use right cache mechanism. For example, if you have both generic (cachable) and personalized (non-cachable) content coming from API, then combining responses on client side can also be considered.

 

Check the below explanation

 

https://youtu.be/cRpE2QtmtLg

nikita24tailorAuthorAccepted solution
Level 4
February 28, 2023

Got the solution for this. Just added cache headers for the graphql in dispatcher and it worked.

Level 4
June 11, 2024

This is the rule which I've added.
# GraphQL cache rules for persistent queries
/0020 {
/glob "/graphql/execute.json/*"
/type "deny"
}