Hi @anny0505
When you say you want to modify the response of a page before you push it to dispatcher, based on what condition you want to modify?
If the content is going to change based on certain condition, then it should not be cached at the dispatcher else user will always get a cached copy once the content is cached at dispatcher.
If it's based on certain query string, you can write a sling model which will be executed on the page component and the same will be displayed to the end user. For this you need to ensure the page is not cached at dispatcher, so you can add the below line in your Java class which will not cache the conent on your dispatcher for the complete page.
To handle which all page can be cached and which all cannot be cached, you can add a boolean property on the page template and using the boolean value you can control the Sling model execution something like below:
Page Component dialog:
<disablecache
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
name="./disableCache"
text="Disable Caching for the Current Page"
deleteHint="{Boolean}true"
fieldDescription="If checked, This Page will not be cached in the dispatcher"
value="true"/>
Page component, include the below line in HTL:
<sly data-sly-use.disableCache="com.aem.core.models.DisableCacheModel"/>
Sling Model:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class DisableCacheModel {
private static final Logger log = LoggerFactory.getLogger(DisableCacheModel.class);
@SlingObject
private SlingHttpServletRequest request;
@ScriptVariable
private Page currentPage;
@PostConstruct
protected void init() {
SlingBindings slingBindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
SlingHttpServletResponse response = slingBindings.getResponse();
if (null != response) {
response.setHeader("Dispatcher", "no-cache");
}
}
}
If you want only certain section content to be dynamic, but the rest all page can be cached, you can use Sling Dynamic Include (SDI)
https://www.argildx.com/technology/sling-dynamic-include-sdi/
Thanks!