Expand my Community achievements bar.

SOLVED

AEM "caching JSP components"

Avatar

Level 7

Hi 

 

Following is setup of our aem environment

AEM Author -> AEM Publisher -> Dispatcher ->CDN -> userbrowser

 

user requests URL : https://company.com/content/siteone/page1.html

 

Issue:

JSP components have calls to "sling.getService()" to get data from backend sources.

Author always displaying data changes.

But dispatcher never displaying the backend data source changes unless republishing of aem pages happen again.

 

Question: Why does this happen? what are my options?

Do I need to say no-cache at service annotation level to make sure always service gets called and latest data retrieved , displayed on front end?

Do I need to do anything else at JSP component level ?

 

I apologize ,if this is a basic question but my knowledge on dispatcher , cdn is limited.

 

Thanks for any help. (I assume above issue would even happen on sightly components as well)

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sreenu539 

Refer below thread and document reference to get a clue on issue and potential resolution - 

Caching in AEM as a Cloud Service | Adobe Experience Manager

Solved: AEMaaCS : Dispatcher/CDN cache - Adobe Experience League Community - 463105

<LocationMatch "^/content/.*\.(html)$">
     Header set Cache-Control "max-age=200"
     Header set Surrogate-Control "max-age=3600"
     Header set Age 0
</LocationMatch>

 

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @sreenu539 

Refer below thread and document reference to get a clue on issue and potential resolution - 

Caching in AEM as a Cloud Service | Adobe Experience Manager

Solved: AEMaaCS : Dispatcher/CDN cache - Adobe Experience League Community - 463105

<LocationMatch "^/content/.*\.(html)$">
     Header set Cache-Control "max-age=200"
     Header set Surrogate-Control "max-age=3600"
     Header set Age 0
</LocationMatch>

 

 

Avatar

Employee Advisor

In your use case, it seems like component behavior is dynamic, ie. the component fetches data from some backend service and renders it. 

There are multiple ways to handle such cases:

  • Lazy loading of your component, using AJAX. Make sure to uncache this AJAX request to always get latest content from backend APIs.
  • Implement SDI (Sling Dynamic Include) [1] for your component. Read this article [2] to understand SDI.

 

[1] https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/development/set-up-sling... 

[2] https://medium.com/tech-learnings/sling-dynamic-include-deep-dive-dynamically-include-page-component... 

Avatar

Employee Advisor

In your case the generated output of AEM is cached in the dispatcher. It's best practice to cache as much as possible to speed up page delivery and also to use a CDN the best way.