Expand my Community achievements bar.

SOLVED

How to remove caching of GraphQL Persisted Query

Avatar

Level 5

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/g... states that GET request in persisted queries are cached. But I don't want my request to be cached. How can I do that?

1 Accepted Solution

Avatar

Correct answer by
Level 5

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

View solution in original post

10 Replies

Avatar

Community Advisor

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/g...

 

Ritesh_Mittal_0-1675517284811.png

 

 

Thanks,

Ritesh Mittal

Avatar

Level 5

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.

Avatar

Community Advisor

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

Avatar

Level 5

Tried but didn't get the required results. I did set the max-age to 0, s-max-age to 0 and stale-while-revalidate to 0. But s-max-age does not change and is reflected as 7200 on publish.

Avatar

Correct answer by
Level 5

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

Avatar

Level 1

Hi @nikita24tailor 

Can you please show how you added the header in dispatcher for GraphQL?

Avatar

Level 1

can u tell what rule u added for the header in dispatcher for GraphQL???

Avatar

Level 1

Please share the headers added for graphql in dispatcher. thank you. 

Avatar

Level 5

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