Asset HTTP json is not cachable in dispatcher docroot | Community
Skip to main content
babusankar
June 28, 2022
Solved

Asset HTTP json is not cachable in dispatcher docroot

  • June 28, 2022
  • 1 reply
  • 2529 views

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.

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?

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 brijesht7477132

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

1 reply

brijesht7477132Accepted solution
Level 2
June 30, 2022

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

babusankar
July 1, 2022

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

Level 2
July 4, 2022

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