Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Automated Dispatcher Cache Clearance

Avatar

Level 1

Hi Everyone!

 

I have an requirement to clear the dispatcher cache only when there is an need to clear them. The dispatcher cache needs to be cleared automatically when I provide an path as input. Kindly help on automating this.

 

Example: When I provide the path as input - htdocs/content/admin/gaja/file.1, the cache has to cleared automatically.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Gaja01 ,

To automate the clearing of the Dispatcher cache for a specific path, you can use the `curl` command to send a `PURGE` request to the Dispatcher. Here's an example of how you can achieve this:

1. Create a script: Create a script that takes the path as input and sends a `PURGE` request to the Dispatcher for that path. Here's an example script:

```bash
#!/bin/bash

# Set the Dispatcher URL
DISPATCHER_URL="http://localhost:80"

# Get the path from the input
PATH=$1

# Send a PURGE request to the Dispatcher for the path
curl -X PURGE "${DISPATCHER_URL}${PATH}"
```

Save this script as `clear-dispatcher-cache.sh` or any other name you prefer.

2. Make the script executable: Make the script executable by running the following command:

```bash
chmod +x clear-dispatcher-cache.sh
```

3. Run the script: Run the script with the path you want to clear the cache for as the input. For example:

```bash
./clear-dispatcher-cache.sh /htdocs/content/admin/gaja/file.1
```

This will send a `PURGE` request to the Dispatcher for the specified path, which will clear the cache for that path.

You can schedule this script to run automatically using a cron job or any other scheduling mechanism. For example, you can schedule it to run every hour or every day to ensure that the cache is cleared regularly.

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @Gaja01 ,

To automate the clearing of the Dispatcher cache for a specific path, you can use the `curl` command to send a `PURGE` request to the Dispatcher. Here's an example of how you can achieve this:

1. Create a script: Create a script that takes the path as input and sends a `PURGE` request to the Dispatcher for that path. Here's an example script:

```bash
#!/bin/bash

# Set the Dispatcher URL
DISPATCHER_URL="http://localhost:80"

# Get the path from the input
PATH=$1

# Send a PURGE request to the Dispatcher for the path
curl -X PURGE "${DISPATCHER_URL}${PATH}"
```

Save this script as `clear-dispatcher-cache.sh` or any other name you prefer.

2. Make the script executable: Make the script executable by running the following command:

```bash
chmod +x clear-dispatcher-cache.sh
```

3. Run the script: Run the script with the path you want to clear the cache for as the input. For example:

```bash
./clear-dispatcher-cache.sh /htdocs/content/admin/gaja/file.1
```

This will send a `PURGE` request to the Dispatcher for the specified path, which will clear the cache for that path.

You can schedule this script to run automatically using a cron job or any other scheduling mechanism. For example, you can schedule it to run every hour or every day to ensure that the cache is cleared regularly.