Search code examples
apachecachingaemdispatcher

What are the best way of handling AEM caching in dispatcher?


I recently came across situation where I need to clear my dispatcher cache manually. For instance, If I am modifying any Js/css files, I would need to clear my dispatcher cache manually in order to get those modified new Js/css else it would be serving the old version of code. I just heard that ACS developed version clientlib which will help us do versioning. I have so many question on this.

Before version clientlib how did AEM manage? Doesn't AEM has intelligent to manage versioned clientlibs? Is it correct of way of handling it? Can we create a Script whil will take back up of the existing before clearing those JS/css files? What are the other options we have?


Solution

  • Versioned clientlib is correct solution. But you ll need bit more:

    • Versioned Clientlibs is a clientside cache busting technique. Used to bust the browser cache.
    • It will NOT bust dispatcher cache. Pages cached at dispatcher continues to serve unless manually cleared.
    • Refer here for similar question.

    To answer your queries:

    • Before version clientlib how did AEM manage? As @Subhash points out, it is part of prod deployment scripts(Bamboo or Jenkins) to clear dispatcher cache when clientlibs change.
    • Doesn't AEM has intelligent to manage versioned clientlibs? - This is same as any cms tools. Caching strategy has to be responsibility of http servers and NOT AEM. Morever when you deploy js code changes, you need to clear dispatcher cache to get pages reflect new js changes.
    • Is it correct of way of handling it? For clientside busting - versioned clientlib is 100% foolproof technique. For dispatcher cache busting, you ll need different method.
    • Can we create a Script while will take back up of the existing before clearing those JS/css files? Should be part of your CI process defined in Jenkins/Bamboo jobs. Not a responsibility of AEM.
    • What are the other options we have? - For dispatcher cache clearance, try dispatcher-flush-rules. You can configure that when /etc design paths are published, they should automatically clear entire tree so that subsequent requests will hit publisher and get updated clientlibs.

    Recommended:

    • Use Versioned Clientlibs + CI driven dispatcher cache clearance.

    Since clientlibs are modified by IT team and requires deployment, make it part of CI process to clear cache. Dispatcher flush rules might help. But it is NOT usecase for someone to modify js/css and hit publish button in production. Production deployment cycle should perform this task. Reference links for dispatcher cache clear scripts: 1. Adobe documentation, 2. Jenkins way, 3. Bamboo way