Caching content fragments json coming from asset api | Community
Skip to main content
Level 2
March 29, 2024
Solved

Caching content fragments json coming from asset api

  • March 29, 2024
  • 3 replies
  • 1019 views

Hi All,

We are using content fragments in our components using asset api. We are directly calling the asset api URL from frontend to get the json for the content fragments. We are trying to cache this json coming from the asset api. 
1. We are unable to cache this json in dispatcher as we were receiving pragma: no-cache and 

Cache-Control: no-store, max-age=0 headers in the response. 
We added a filter to override these headers. With the filter we are able to cache the json which had less data/content but for bigger json were still getting the pragma: no-cache headers. We are unable to figure out why is happening. 
2. As an alternative we added a custom servlet to call the asset api instead of calling it directly
.
We are able to cache the servlet response but the problem with this is the cache invalidation.
The cached json is not getting flushed when we publish the content fragments  or publish the page. 
 
Any suggestions/ input would be greatly appreciated!"
Thank you
 
 
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 Jineet_Vora

@ayushn - For the second approach, have you tried using max-age with must-revalidate?
e.g. 

Cache-Control: max-age=3600, must-revalidate

3 replies

Jineet_Vora
Community Advisor and Adobe Champion
Jineet_VoraCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
March 29, 2024

@ayushn - For the second approach, have you tried using max-age with must-revalidate?
e.g. 

Cache-Control: max-age=3600, must-revalidate
sateaswa94
Level 3
April 1, 2024


Create a ResourceChange Listener to the content fragment folder path and clear the dispatcher cache for your servlet path DispatcherFlusher service. Limitation with this approach is dispatcher cache will be removed regardless of any cf get updated under the given path.

Anudeep_Garnepudi
Community Advisor
Community Advisor
April 2, 2024

@ayushn 

 

What all paths and patterns that you configured in filter? Make sure your content fragment path and extension (json) are targeted in Filter.

 

I don't think you need to write a servlet again as you already have filter in place.

 

Whichever way you are handling (Filter/Servlet) to expire the cache the default behavior (flush on publish) will still work. If not working check your dispatcher invalidate rules for your content fragment path.