Clear AEM DAM Content Cache with Curl
Step 1: Write a Script to Hit the Endpoint
Access CRXDE Lite
- Navigate to
CRXDE Litein your AEM instance. - Go to
libs > workflow > scripts. - Create a new file with a
.ecmaextension.
Paste the Following Script
- (Replace the URL in the
curl command according to your needs.)
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);
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
Createbutton, fill in theTitleandName, then clickDone.
Edit the Workflow Model
- Select your model and click the
Editbutton. - Delete the previously added component.
- Add the
Online Process Stepcomponent.
Configure the Process Step
- Click on the
Process Stepand then theConfigurebutton. - Go to the
Processtab. - In the
Processdropdown, select the script file you added in CRXDE Lite. - Check the
Handler Advanceoption and enable it. - Click the
Syncbutton on the top left corner.
Step 3: Create a Workflow Launcher
Access Workflow Launchers
- Go to
Tools > Workflow > Launchers. - Click the
Createbutton and add a new launcher.
Configure the Launcher
- In
Event Type, selectModified. - In
NodeType, selectdam:Asset. - In
Path, select the folder path where your content is saved. - In
Workflow, select the workflow model you created. - Check the
Activatebutton. - Click
Save & Close.
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



0 comments: