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

Avatar

Avatar
Validate 1
Level 1
aem-enthusiast
Level 1

Likes

0 likes

Total Posts

8 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
aem-enthusiast
Level 1

Likes

0 likes

Total Posts

8 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
aem-enthusiast
Level 1

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
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
SureshDhulipudi
MVP

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
Springboard
MVP
Shashi_Mulugu
MVP

Likes

232 likes

Total Posts

294 posts

Correct reply

67 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Applaud 100
Establish
View profile

Avatar
Springboard
MVP
Shashi_Mulugu
MVP

Likes

232 likes

Total Posts

294 posts

Correct reply

67 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Applaud 100
Establish
View profile
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