Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Event handler using Job Manager or Replication Agent with Transport Handler and Content Builder

Avatar

Level 4

We are looking for a implementation to send invalidating cache(with content path info) info to external system .. Is there any advantage of using one of the above implementation over the other ? Or when would you prefer one over the other ?

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @AEMnewbie ,
The use of these api are different. 
Event Handling using JobManager and JobConsumer used for event handling. These api give you at least guarantee of execution once. 
Transport Handler api are used for replication purpose at high level. 
If you want to initiate cache invalidation on some event programatically then try to use specific event handler ex. for page update/page replicated. You you want to invalidate dispatcher, you can trigger cache flush using code with existing dispatcher flush again. 
If you are using some third party caching(ex . Akami), I believe there are api available for that. 


If you want to create a custom replication agent for third party to invalidate cache then you might need TransportHandler api.

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @AEMnewbie ,

AEM already have functionality for invalidating cache(dispatcher flush agent) and that is recommended to use always as possible. 

However, each entity may need some customization for some reason - in this case if you still want to export content path info, you have plenty of options to achieve it. One that suits here is 

  • Event Listener 
  • JCR Observer

You can implement and trigger it based on page activation then perform passing them to external agency though servlet API.

Piece of code sharing here for the same 

try{
      //retrieve the request parameters
      String handle = request.getParameter("handle");
      String page = request.getParameter("page");

      //hard-coding connection properties is a bad practice, but is done here to simplify the example
      String server = "localhost";
      String uri = "/dispatcher/invalidate.cache";

      HttpClient client = new HttpClient();

      PostMethod post = new PostMethod("https://"+host+uri);
      post.setRequestHeader("CQ-Action", "Activate");
      post.setRequestHeader("CQ-Handle",handle);

      StringRequestEntity body = new StringRequestEntity(page,null,null);
      post.setRequestEntity(body);
      post.setRequestHeader("Content-length", String.valueOf(body.getContentLength()));
      client.executeMethod(post);
      post.releaseConnection();
      //log the results
      logger.info("result: " + post.getResponseBodyAsString());
      }
  }catch(Exception e){
      logger.error("Flushcache servlet exception: " + e.getMessage());
  }

Reference: https://github.com/AdobeDocs/experience-manager-dispatcher.en/blob/main/help/using/page-invalidate.m...

 

Hope that helps!

Regards,

Santosh

 

Avatar

Correct answer by
Community Advisor

Hi @AEMnewbie ,
The use of these api are different. 
Event Handling using JobManager and JobConsumer used for event handling. These api give you at least guarantee of execution once. 
Transport Handler api are used for replication purpose at high level. 
If you want to initiate cache invalidation on some event programatically then try to use specific event handler ex. for page update/page replicated. You you want to invalidate dispatcher, you can trigger cache flush using code with existing dispatcher flush again. 
If you are using some third party caching(ex . Akami), I believe there are api available for that. 


If you want to create a custom replication agent for third party to invalidate cache then you might need TransportHandler api.