Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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 @Vikram_Gaur_ 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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...

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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...

 

 

Avatar

Community Advisor

@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