내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Disabling dispatcher cache for some pages with HTTP header

Avatar

Level 2

This document tells that but on JSP. I wonder how to do it on a java model?

주제

토픽은 커뮤니티 콘텐츠를 분류하여 관련성 있는 콘텐츠를 찾는 데 도움이 됩니다.

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 8

Hi @MaynorSong,

If you want to disable caching your pages in dispatcher, you can add rule in dispatcher config file as mentioned here.

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-c...

 

If you want handle this through AEM backend then below are the 2 options.

1. To disable dispatcher caching the pages in which specific component is added, set response header in that specific component model class.

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ComponentModel {

@Inject
private SlingHttpServletResponse response;

@PostConstruct
protected void init() {
response.setHeader("Dispatcher", "no-cache");
}
}

 

2. If you have this use case for specific pages not by specific component basis, then create common cache control model class & include call to that model class in page footer level based on page condition check.

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CacheControlModel {

@Inject
private SlingHttpServletResponse response;

@PostConstruct
protected void init() {
response.setHeader("Dispatcher", "no-cache");
}
}

 

HTML

<sly data-sly-test="${condition}" data-sly-use="com.project.core.models.CacheControlModel"/>

 

 

Hope this helps!

원본 게시물의 솔루션 보기

4 답변 개

Avatar

Community Advisor

you can use the same with in java method-  SlingHttpServletResponse response

 

response.setHeader("Dispatcher", "no-cache");

Avatar

정확한 답변 작성자:
Level 8

Hi @MaynorSong,

If you want to disable caching your pages in dispatcher, you can add rule in dispatcher config file as mentioned here.

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-c...

 

If you want handle this through AEM backend then below are the 2 options.

1. To disable dispatcher caching the pages in which specific component is added, set response header in that specific component model class.

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ComponentModel {

@Inject
private SlingHttpServletResponse response;

@PostConstruct
protected void init() {
response.setHeader("Dispatcher", "no-cache");
}
}

 

2. If you have this use case for specific pages not by specific component basis, then create common cache control model class & include call to that model class in page footer level based on page condition check.

@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CacheControlModel {

@Inject
private SlingHttpServletResponse response;

@PostConstruct
protected void init() {
response.setHeader("Dispatcher", "no-cache");
}
}

 

HTML

<sly data-sly-test="${condition}" data-sly-use="com.project.core.models.CacheControlModel"/>

 

 

Hope this helps!

Avatar

Community Advisor

One top of @Manjunath_K, if you wanted it for page then you can also set a servlet filter based on page type and then from filter you can add or remove headers add needed.

Can you please chek below article from Preeti

https://medium.com/@preeti.bhaya/dispatcher-caching-based-on-resource-types-afc712e6f5ef

 

Hope this will help.

Umesh Thakur

Avatar

Level 8

You can check the below approaches.

Enable it for the page:

If you want to disable cache for only a specific set of pages, then you can follow the below approach. in the page, properties put a checkbox, and on the selection of checkbox just load the below JSP file.

<sly data-sly-include="no-cache.jsp" />

Inside the .jsp file call no-cache code.

Enable it for components:

I recommend you to use sling dynamic include for the dynamic components, it gives a lot of advantages when we compare with other approaches. you don't need to set response headers in the sling model, all you need to do is just configuration, check below article for more information.

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