AEM 6.5 : Update image asset URL at runtime to bust CDN cache

Avatar

Avatar

aem-enthusiast

Avatar

aem-enthusiast

aem-enthusiast

20-11-2020

Hi,

We have a requirement where we need to render the last updated image asset on the page. The issue is that CDN cache is configured and it will not serve the most recently updated asset as it will be invalidated only after 180 days. 

In order to render the most recent asset, we need to do something programmatically to always render the most recently updated image. One suggestion was to append the last updated date to the image name at runtime to invalidate the cache. But need some details around this as to how this works and how to implement this programmatically.

Has anybody done this kind of an implementation? Appreciate your help on this.

Thanks 

@Vish_dhaliwal @vanegi @VikramGaur 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

sureshd71454102

Avatar

sureshd71454102

sureshd71454102

21-11-2020

Two scenarios can apply

1) In one of our use case, we implemented a workflow that will trigger when an asset is modified to Invalidate CDN cache

public void execute(final WorkItem workItem, final WorkflowSession workflowSession, final MetaDataMap arg)
throws WorkflowException {
try {
Asset asset = getAssetFromPayload(workItem, workflowSession.adaptTo(Session.class));

ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(
Collections.singletonMap("sling.service.subservice", (Object)EAEM_CACHE_INVALIDATION_PROCESS));

 

CdnCacheInvalidationParam cacheInvalidationParam = getCdnCacheInvalidationParam(config, asset);

=========

 

2) Did you check the  AdaptiveImageServlet --> requestLastModifiedSuffix = getRequestLastModifiedSuffix(suffix);

https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq...

 

 

Answers (1)

Answers (1)

Avatar

Avatar

Shashi_Mulugu

MVP

Avatar

Shashi_Mulugu

MVP

Shashi_Mulugu
MVP

22-11-2020

@aem-enthusiast we can have CDN cache clearing in many ways?

 

1. Via workflow: can be manually triggered or can be clubbed with publish workflow if you already have one.

 

2. Replication Preprocesser

3. Replication event listener 

3. Replication custom flush agent