AEM "caching JSP components" | Community
Skip to main content
sreenu539
Level 7
September 6, 2022
Solved

AEM "caching JSP components"

  • September 6, 2022
  • 3 replies
  • 1241 views

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)

 

 

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 Nitin_laad

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>

 

 

3 replies

Nitin_laad
Community Advisor
Nitin_laadCommunity AdvisorAccepted solution
Community Advisor
September 6, 2022

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>

 

 

Mohit_KBansal
Adobe Employee
Adobe Employee
September 7, 2022

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-dynamic-include.html?lang=en 

[2] https://medium.com/tech-learnings/sling-dynamic-include-deep-dive-dynamically-include-page-components-in-aem-5420a696cd02 

joerghoh
Adobe Employee
Adobe Employee
September 9, 2022

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.