Clear AEM DAM Content Cache with Curl
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.)
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
Create
button, fill in theTitle
andName
, then clickDone
.
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 theConfigure
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
, 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
Activate
button. - 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: