Expand my Community achievements bar.

SOLVED

Invalidate Dispatcher and CDN Cache on AEM Cloud

Avatar

Level 2

Did anyone come across a need to clear/invalidate Dispatcher and CDN cache completely on AEM Cloud instance. I found couple of example for single path/URL but nothing concrete on complete cache. Any help on this would be appreciated.

Note:

Changing stat level is not an option and yes we do need a complete cache clear

1 Accepted Solution

Avatar

Correct answer by
Level 3

Adobe cloud is using Fastly. Fastly provides an API to purge cache https://developer.fastly.com/reference/api/purging/

You have to develop custom code to purge cache using API. You for example can create a workflow by using which you can purge the cache by  API’s purge service or tags option.

Similarly Akamai (another CDN vendor) provides an API to purge cache by using CP code or tags but to invoke it from AEM certainly custom code is required. 
I will suggest it should be via a workflow which you can be invoked only when needed.

 

 

View solution in original post

10 Replies

Avatar

Employee Advisor

Hi @omkar20xx1!

While caching is a pretty easy task, cache invalidation is a lot harder to do - at least if you are trying to do it efficiently. Active invalidation of the CDN is a tricky problem because the publish tier of AEM Cloud Services is eventually consistent. Depending on your exact requirements for caching, there might be no perfect solution at all that will be both, consistent (meaning 100% reliable) and efficient (meaning invalidating only what's necessary and no duplicate invalidations).

In addition to that, there are certain implications that you definitely do want to take into account if you are still considering active and complete invalidation of all caching layers involved for AEM CS. This will most probably have direct effect on the load and performance of the publish tier.

The overall recommendation is to leverage TTL configurations (even if set to low values of few minutes) and tailor them to the different update cycles of the resources being cached and delivered to the end user.

This leads to my disclaimer: Please handle active cache invalidation with care, be cautious about the effects it will have!

 

That being said, I have not yet seen a readily-available solution for a complete cache purge on CDN level.

You may want to explore the following community article that covers invalidation of specific paths on both, Dispatcher and CDN level for AEM CS:

You might be able to build on the outlined solution to create a "batch" invalidation of multiple paths or to explore options even beyond that.

 

Hope this helps!

Avatar

Level 2

I have been though this blog already. Though this talks about invalidating single URL as such. Any header or pattern that gives a complete flush or soft purge for CDN. Any method or class which invalidates entire dispatcher cache like giving a root path or something within the SCD API

Avatar

Employee Advisor

@omkar20xx1 wrote:

Though this talks about invalidating single URL as such.


That is correct, the outlined solution is only taking care of a single path. You could build up on it and iterate through multiple paths, though. (That's what I was referring to as "batch processing" in my initial answer.) Be aware of the load this might cause on both ends, AEM and the CDN, though.

 


@omkar20xx1 wrote:

Any header or pattern that gives a complete flush or soft purge for CDN.


I'm not aware of an option for a complete cache purge on CDN level. While the Fastly API does provide different purge options, all of them are targeted at specific parts of the cached content. I'm not an in-depth Fastly expert but would assume that there simply might be no option for a complete purge - which makes perfect sense as the approach to caching and cache invalidation usually works differently (with TTLs being the recommended way to handle cache invalidation on that level).

 


@omkar20xx1 wrote:

Any method or class which invalidates entire dispatcher cache like giving a root path or something within the SCD API


Invalidating the Dispatcher cache is certainly possible. For AEM 6.5 (on-premise or AMS), this can easily be achieved by deleting files from the caching folder on the files system or sending a request to the dispatchers invalidation endpoint.

For AEM CS, things get a bit more tricky but you should still be able to leverage some of the techniques from this page. Especially the Flush Servlet might come in handy, although it would need some modifications to achieve this - and potentially also some batch processing.

 

The other important question is if this is a one-off thing you need or if your aim is to clear the cache on a regular basis. For the latter, you might want to re-evaluate the statsfile level option. Also, I'd highly recommend to re-evaluate the underlying requirement for a repeated complete cache deletion as this is an anti-pattern. For regular setups of AEM, this should not be needed and is not recommended.

 

Hope this helps!

Avatar

Level 2

Yes this is something we would need to do at certain intervals. Not very regularly. May be once in a month.

Avatar

Employee Advisor

This is definitely a red flag!

 

If your business or technical workflows do require a hard and full deletion of all cache layers on a regular basis, there is a strong need to re-evaluate and optimize these workflows. A properly designed AEM setup does not require this. It is - in the best case - a workaround for sub-optimal processes, taking care of symptoms rather than root causes.

 

Therefore I'd highly recommend to spend your efforts fixing the cause rather than developing workarounds for the symptoms you might be experiencing.

 

Please feel free to provide additional background and details on why you do think the cache clean might be necessary. What are the use cases you have in mind? What's the goal?

That way, the community might be able to guide you towards a better solution.

Avatar

Level 3

Can you please describe which CDN system you have?

Akamai for example provides an API to invalidate complete cache by using cp code.

It is also possible to implement cache tags in case you want to clear only specific file types for example html only.

 

Avatar

Level 2

We currently have the OOTB CDN adobe provides with AEM cloud. On top of it. We have our own CDN. It is basically just a wrapper and forwards the request most of the time.

Avatar

Correct answer by
Level 3

Adobe cloud is using Fastly. Fastly provides an API to purge cache https://developer.fastly.com/reference/api/purging/

You have to develop custom code to purge cache using API. You for example can create a workflow by using which you can purge the cache by  API’s purge service or tags option.

Similarly Akamai (another CDN vendor) provides an API to purge cache by using CP code or tags but to invoke it from AEM certainly custom code is required. 
I will suggest it should be via a workflow which you can be invoked only when needed.

 

 

Avatar

Administrator

@omkar20xx1 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni