Jenkins Job to clear dispatcher cache of single/multiple page(s)

Sometimes we receive requests to clear the dispatcher cache for a specific page. However, in most cases, we don't have the option to clear the cache for individual pages, so we end up clearing the entire dispatcher cache. This approach leads to heavy traffic on the production publisher instances and increased CPU utilization.

To tackle this problem, I developed a dedicated Jenkins job that focuses on clearing the dispatcher cache for single or multiple pages. With this new job, we no longer have to clear the entire dispatcher cache whenever a request for page-specific cache clearing arises.

This improvement brings about a significant reduction in traffic on the publishing instances and alleviates CPU utilization, especially when it's unnecessary to clear the entire dispatcher cache.

Notes:

1) Enter the path as AEM full publisher/author path ending with .html as the location where the page will be stored in dispatcher
2) Multiple page paths can be entered in new lines
3) All modified/updated pages in publisher will be cleared from dispatcher along with the page path provided.

Add below code in Jenkins Execute shell section by updating the parameters accordingly:

 #!/bin/bash

#Assigning a path for curl command.

CURL='/usr/bin/curl'

#[Dev Dispatcher] Server Addresses and descriptions

DEV_DISPATCHER='*.*.*.*'

DEV_DESCRIPTION='DEV DISPATCHER'

echo ""

echo "Running Page(s) Dispatcher Cache Clear Script"

echo ""

echo ""

#ENVIRONMENT is passed as parameterized value

echo "Environment selected ${ENVIRONMENT}"

#We can add multiple environments based on the ENVIRONMENT parameter selected

#$PagePath - is passed as parameterized value, we can pass multiple paths in new lines

#Path should be starting with /content and end with .html

#Repeat the if condition until fi for adding new environment and update the parameter values accordingly

if [ "$ENVIRONMENT" == "DEV" ]; then

for pagePaths in $PagePath; do

echo "Clearing cache for ${DEV_DESCRIPTION} with IP Address (${DEV_DISPATCHER}) at ${pagePaths}"

echo ""

#Replace dev.example.com - with actual DNS name 

${CURL} -X PURGE -H "Host: dev.example.com" -H "CQ-Action: ACTIVATE" -H "CQ-Handle: ${pagePaths}" -H "CQ-Path: ${pagePaths}" -H "Content-Type: text/plain" "http://${DEV_DISPATCHER}/dispatcher/invalidate.cache"

echo ""

echo ""

done

fi

EXIT_STATUS=$?

if [[ ${EXIT_STATUS} -eq 0 ]]; then

  exit 0

else

  exit 1

fi

Comments

Popular posts from this blog

AEM integration with Akamai Fast Purge API for Single/multiple urls

AEM Results count using query builder

AEM - Rollout a page programmatically and update references