Expand my Community achievements bar.

SOLVED

How to clear Dispatcher cache?

Avatar

Level 7

Hi Team,

 

I'm checking on ways of clear the dispatcher cache in AEM and I will list the ways I know .. Please explain more about them as well as anything else ...

 

  • Custom code to do the flush through programming using API end point 
  • Through dispatcher flush agent 
  • using invalidate property through cache section 
  • using statfileslevel property through cache section 

Thanks in advance! 

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @JakeCham 

Sure, I'd be happy to explain those ways to clear the Dispatcher cache in AEM.

  1. Custom code to do the flush through programming using API end point: You can use the /bin/flushmanager.html endpoint in AEM to programmatically clear the Dispatcher cache. Here's an example of how you might do this using curl

    curl -u username:password "AEM_PUBLISH_URL/bin/flushmanager.html?cmd=flushall"
  2. This command will clear the entire Dispatcher cache for the AEM publish instance.

    1. Through dispatcher flush agent: AEM provides a built-in flush agent that can be used to clear the Dispatcher cache. You can enable this agent by setting the DISPATCHER_FLUSH_AGENT parameter to true in the agent.properties file of your AEM instance. Once enabled, the flush agent will clear the Dispatcher cache whenever a page is activated or deactivated.

    2. using invalidate property through cache section: You can use the invalidate property in the dispatcher.any file to specify which files or pages should be cleared from the Dispatcher cache when a page is activated or deactivated. Here's an example of how you might use this property:
      /cache/invalidate {
      /0000 {
      /glob "*"
      /type "allow"
      }
      }

      This configuration will clear all files in the Dispatcher cache when a page is activated or deactivated.

      1. using statfileslevel property through cache section: The statfileslevel property in the dispatcher.any file determines how often the Dispatcher checks the timestamps of the .stat files in the cache. By default, this property is set to 0, which means that the Dispatcher checks the .stat files every time a request is made. However, you can set this property to a higher value (e.g. 1) to reduce the frequency of these checks and improve performance.
    3. Here's an example of how you might use this property:
       /cache {
      /statfileslevel 1
      }


      This configuration will tell the Dispatcher to check the .stat files every 5 seconds, instead of every request.

      I hope that helps! Let me know if you have any other questions.

View solution in original post

8 Replies

Avatar

Level 4

Hi @JakeCham 

 

  1. Custom Code: Within AEM, you can write custom code to programmatically invalidate or flush a specific Dispatcher cache item. This usually involves leveraging Adobe's HTTP API to carry out a specific HTTP action, which is POST, and pass specific arguments like ":action=InvalidateDispatcherCache". The cache item URL is part of the POST call.

  2. Dispatcher Flush Agent: flush agents in AEM are another key method. A flush agent is set up on Author to "detect" when certain content is activated (or deactivated), then triggers the Dispatcher to flush the associated cache item. To set this up, you must go to Tools => Operations => Web Console (or Tools => Operations => Replication) to configure your flush agent. This is a built-in feature of AEM.

  3. Invalidate property in the cache section of Dispatcher: Another way to manage cache is through Dispatcher's configuration file, dispatcher.any. In the /cache section, there's 'invalidate' property, which controls whether Dispatcher should automatically drop related cached files when an incoming request modifies the content on the publish instance. It's good for managing cache globally and systematically.

  4. Statfileslevel property in the cache section of Dispatcher: 'statfileslevel' is another property listed in the /cache section of the dispatcher.any file. It controls the directory level at which the Dispatcher writes the .stat files. The .stat file is used to define the time at which the cache was last adjusted. If Dispatcher receives an activation request, or the statfile is newer than the cache file, the cached file is re-requested from the publish instance.

Also you can write a schedular to clear the cashe on everyday bases.

 

Thanks,

Venkat

Avatar

Community Advisor

ACS Commons to clear dispatcher cache:

https://medium.com/@toimrank/enable-or-disable-dispatcher-cache-9ce071810420

 

Custom cache clearance using Distribution request

DistributionRequest distributionRequest = new SimpleDistributionRequest(requestType,
isDeep, pathsToInvalidate.toArray(new String[0]));
if (!pathsToInvalidate.isEmpty()) {
DistributionResponse distributionResponse = distributor.distribute(agent,
resolver, distributionRequest);
LOGGER.debug("Distribution message: {}", distributionResponse.getMessage());
}

Avatar

Community Advisor

You can also use acs-commons dispatcher flush to clear the cache. It has 2 options invalidate and delete the cache.

https://adobe-consulting-services.github.io/acs-aem-commons/features/dispatcher-flush-ui/index.html

Avatar

Level 3

Do you have experience using this in production on an AEMaaCS instance?  Curious how well it works for ad-hoc dispatcher flushes. 

Avatar

Community Advisor

Hi @JakeCham 

This will provide you with additional information regarding flush strategies.

Deep-dive into AEM dispatcher’s cache flush strategies

Thanks 

Avatar

Administrator

@JakeCham Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Correct answer by
Level 4

Hi @JakeCham 

Sure, I'd be happy to explain those ways to clear the Dispatcher cache in AEM.

  1. Custom code to do the flush through programming using API end point: You can use the /bin/flushmanager.html endpoint in AEM to programmatically clear the Dispatcher cache. Here's an example of how you might do this using curl

    curl -u username:password "AEM_PUBLISH_URL/bin/flushmanager.html?cmd=flushall"
  2. This command will clear the entire Dispatcher cache for the AEM publish instance.

    1. Through dispatcher flush agent: AEM provides a built-in flush agent that can be used to clear the Dispatcher cache. You can enable this agent by setting the DISPATCHER_FLUSH_AGENT parameter to true in the agent.properties file of your AEM instance. Once enabled, the flush agent will clear the Dispatcher cache whenever a page is activated or deactivated.

    2. using invalidate property through cache section: You can use the invalidate property in the dispatcher.any file to specify which files or pages should be cleared from the Dispatcher cache when a page is activated or deactivated. Here's an example of how you might use this property:
      /cache/invalidate {
      /0000 {
      /glob "*"
      /type "allow"
      }
      }

      This configuration will clear all files in the Dispatcher cache when a page is activated or deactivated.

      1. using statfileslevel property through cache section: The statfileslevel property in the dispatcher.any file determines how often the Dispatcher checks the timestamps of the .stat files in the cache. By default, this property is set to 0, which means that the Dispatcher checks the .stat files every time a request is made. However, you can set this property to a higher value (e.g. 1) to reduce the frequency of these checks and improve performance.
    3. Here's an example of how you might use this property:
       /cache {
      /statfileslevel 1
      }


      This configuration will tell the Dispatcher to check the .stat files every 5 seconds, instead of every request.

      I hope that helps! Let me know if you have any other questions.