Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

AEM Cloud : How to not cache the GraphQL persistent queries

Avatar

Level 4

Hi Team,

 

In my website, I am using GraphQL queries on Content Fragments. When I am creating new CF's and publishing it, I am not able to fetch those CF's on my publisher website using GraphQL queries.

 

After 1 or 2 days, I am able to read them so my question is, how can I remove caching for GraphQL queries so I would get new fragments data as well?

 

I checked the dispatcher settings and found that the default rewrite rule is allowing cache for GraphQL like this


# Allow the dispatcher to be able to cache persisted queries - they need an extension for the cache file
RewriteCond %{REQUEST_URI} ^/graphql/execute.json
RewriteRule ^/(.*)$ /$1;.json [PT]

 

I updated the cache rule as well in dispatcher repo to overwrite the above caching, but it is still not working on publisher
/2003
{
/glob "/graphql/execute.json/*"
/type "deny"
}

 

What could be the best way to not cache the queries.

 

Thanks.

 

6 Replies

Avatar

Level 5

Hi @SDusane ,

 

You can try below things:-

 

1. You can add below dispatcher rule to deny cache.

# It will block caching for GraphQL responses
/0001 {
/glob "/graphql/execute.json*"
/type "deny"
}

 

2. You can flush Dispatcher Cache After CF Publish - Configure Dispatcher Flush Agent (Replication Agent) on publish instance, specifically flush GraphQL cache upon CF activation.

 

3. You can add this inside your virtual host or dispatcher farm: This will force browser not to cache GraphQL response.

<LocationMatch "^/graphql/execute.json.*$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</LocationMatch>

Let me know if it works.

Thanks.

 

Avatar

Community Advisor

@SDusane Use no-cache header
<LocationMatch "^/content/graphql/.*">
          Header always set Cache-Control "no-store, no-cache, must-revalidate, private"
          Header always set Pragma "no-cache"
          Header always set Expires "0"
</LocationMatch>

 

/content/graphql --> It should be GraphQL path in your project

 

2. Deny as part of dispatcher rule:

/rules {
/0001 { /glob "*/graphql/*" /type "deny" } }

Avatar

Level 4

Hi @Imran__Khan and @ShivamKumar ,

 

I tried both things like 

1. Updating the vhost file with no cache header, giving the code below :

# Allow no caching for GrpahQL Persisted Queries API
<LocationMatch "^/graphql/execute.json.*$">
Header always set Cache-Control "no-store, no-cache, must-revalidate, private"
Header always set Pragma "no-cache"
Header always set Expires "0"
</LocationMatch>

 

2. I have already added the rule to deny the caching

/2003
{
/glob "/graphql/execute.json/*"
/type "deny"
}

 

3. I updated the headers for queries GrpagQL Query Editor portal > Select ... from the query > select Headers > Update Cache-control to 0 sec value > Publish the query.

 

SDusane_0-1745974927149.png

 

But I could see its still not working, pls help me to find the correct solution.

 

Thanks.

 

 

Avatar

Level 5

I think if it is not cached on dispatcher it can be cached on CDN.

 

Please try addding these headers and check again -

<LocationMatch "^/graphql/execute.json.*$">
Header always set Cache-Control "no-store, no-cache, must-revalidate, private"
Header always set Pragma "no-cache"
Header always set Expires "0"
Header always set Surrogate-Control "no-store"
</LocationMatch>


Surrogate-Control: no-store is what instructs Fastly (or CDN) not to cache the response.

Avatar

Community Advisor

@SDusane Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!


Aanchal Sikka

Avatar

Level 4

I am still looking for solution, it is still not working after doing this changes.