Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Asset HTTP json is not cachable in dispatcher docroot

Avatar

Level 1

Hello Techies,

 

I am making a series of calls from graphql (which is placed outside AEM, consider it as 3rd party) via Dispatcher to my publish instance like

http://my-publish-domain/api/assets/my/content_fragment/path.json.

I could get the result as json, but this response is not getting cached in dispatcher docroot.

 

 

On a deeper look i could see in dispatcher logs says like below and these json results are never cached.

 

Backend forbids caching, sent: 'Pragma: no-cache'

 

 

Further the publish instance directly (not through dispatcher) itself give following Response header.

Not sure this is causing the issue of not caching in dispatcher.

Asset_Api_http_calls_header.png

My Query

Can it be customised so that we can cache the .json result, because every-time when a page is refreshed always the Asset API calls reaches the origin server?

1 Accepted Solution

Avatar

Correct answer by
Level 3

Hi @babusankar : Sorry by mistake I pressed the button me too. I am not having this issue.

It Pragma header will be causing this issue. You can raise this issue with Adobe but as a workaround, you can create a Java Servlet filter and put conditions for the asset API remove this Pragma header once the response is ready to send from publisher to webserver (for reference: https://www.codejava.net/java-ee/servlet/how-to-create-java-servlet-filter)

Hoping it will be of some use for you

View solution in original post

4 Replies

Avatar

Correct answer by
Level 3

Hi @babusankar : Sorry by mistake I pressed the button me too. I am not having this issue.

It Pragma header will be causing this issue. You can raise this issue with Adobe but as a workaround, you can create a Java Servlet filter and put conditions for the asset API remove this Pragma header once the response is ready to send from publisher to webserver (for reference: https://www.codejava.net/java-ee/servlet/how-to-create-java-servlet-filter)

Hoping it will be of some use for you

Avatar

Level 1

Hi @brijesht7477132 ,

 

Firstly thank you for your time on this and reply.

 

I implemented a Java Servlet Filters with /api/assets pattern and was able to capture the request & response objects.

However what i observed are

  • New Header are added successfully
  • Tried using SetHeader and addHeader to response object but still getting the header values as mentioned and attached in my original post.

My rough guess is that the Java Servlet Filter (first candidate) is trying to set the response header, which are again rewritten by the AEM OOTB Servlet/Filter/Service (last candidate) that corresponds to /api/assets API before handing over to dispatcher.

 

So the flow is like

Client(Browser) --> Dispatcher --> Java Servlet Filter --> AEM OOTB Servlet/Filter/Service

which finally lands to the same situation.

 

Attaching capture of code and dispatcher logs for better clarity

Screenshot 2022-07-01 at 17.46.39.pngScreenshot 2022-07-01 at 17.53.33.png

Avatar

Level 3

Hi @babusankar ,

 

Here is the catch you have to update pragna header after the filterChain.doFilter(); method.

Meaning you are updating the header after the request is process.

Th flow should be Client(Browser) --> Dispatcher --> Java Servlet Filter --> AEM OOTB Servlet/Filter/Service  --> Java Servlet Filter --> Dispatcher --> Client(Browser)

 

Hoping this will solve your problem

 

Avatar

Level 1

I was having the scope of the Sling Servlet as REQUEST but it should be FORWARD to get the headers working.

 

Thanks for all the efforts. Closing the ticket