Tuesday, August 22, 2023

How to Clear AEM DAM Content Cache with Curl

Clear AEM DAM Content Cache with Curl




Clearing the cache of AEM DAM content is essential for ensuring up-to-date content delivery. You can automate this process using a workflow that hits an external endpoint. Here’s a step-by-step guide on how to do it:


Step 1: Write a Script to Hit the Endpoint

Access CRXDE Lite

  • Navigate to CRXDE Lite in your AEM instance.
  • Go to libs > workflow > scripts.
  • Create a new file with a .ecma extension.

Paste the Following Script

  • (Replace the URL in the curl command according to your needs.) 

var processBuilder = new Packages.java.lang.ProcessBuilder(
"curl",
"--insecure",
"--location",
"--request",
"POST",
"--show-error",
"--header",
"Cookie: 03169bf6399c3d57d98e19254b71a5b4=52352d23a6524ddcb81702c34b3b7e52",
"https://message-service-route-mybusiness-ee-dev.apps.ocp-dev.stc.com.sa/internal/v1/messages/flush"
);
var process = processBuilder.start();
var inputStream = process.getInputStream();
var scanner = new Packages.java.util.Scanner(inputStream).useDelimiter("\\A");
var output = scanner.hasNext() ? scanner.next() : "";
var errorStream = process.getErrorStream();
var errorScanner = new Packages.java.util.Scanner(errorStream).useDelimiter("\\A");
var errorOutput = errorScanner.hasNext() ? errorScanner.next() : "";
var exitCode = process.waitFor();
var responseCode = exitCode === 0 ? 204 : exitCode;
log.info("Dam Content Cache Cleared Successfully . . .: " + responseCode);


Step 2: Create a Workflow Model


Access Workflow Models

  • Go to Tools > Workflow > Models.
  • Click on the Create button, fill in the Title and Name, then click Done.

Edit the Workflow Model

  • Select your model and click the Edit button.
  • Delete the previously added component.
  • Add the Online Process Step component.

Configure the Process Step

  • Click on the Process Step and then the Configure button.
  • Go to the Process tab.
  • In the Process dropdown, select the script file you added in CRXDE Lite.
  • Check the Handler Advance option and enable it.
  • Click the Sync button on the top left corner.

Step 3: Create a Workflow Launcher


Access Workflow Launchers

  • Go to Tools > Workflow > Launchers.
  • Click the Create button and add a new launcher.

Configure the Launcher

  • In Event Type, select Modified.
  • In NodeType, select dam:Asset.
  • In Path, select the folder path where your content is saved.
  • In Workflow, select the workflow model you created.
  • Check the Activate button.
  • Click Save & Close.



When you make any changes to your targeted assets, the workflow will automatically start and clear the cache. let you see I made some changes in the DAM Content and the workflow for cache clearing is auto executed





By following these steps, you can ensure your AEM DAM content cache is cleared efficiently using Curl and automated workflows.



Conclusion

Implementing this automated workflow for clearing the DAM content cache in AEM can significantly enhance your content management process. Regular cache clearing ensures that the latest content is always delivered to your users.

Thanks for reading!



Thanks
Previous Post
Next Post

post written by:

0 comments: