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!