Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Caching content fragments json coming from asset api

Avatar

Level 2

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
 
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

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

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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

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

Avatar

Level 3


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.

Avatar

Community Advisor

@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.