Event handling in AEMaaCS / Run Java code after publish
What is the best way to tap into and run a bit of Java code whenever a publish occurs in AEMaaCS?
I have an API servlet that is fetching and returning some structured content from AEM. This servlet uses Caffeine to cache some computations in memory for an hour so that results don't get recomputed on every request. When a publish occurs in AEM, I want to run a function to clear this cache.
I tried the following but it doesn't appear to get triggered (at least locally). What's the best way to trigger a bit of Java code to run after a publish occurs?
@8220494(service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=com/adobe/granite/content/replication/end"
})
public class CustomPublishEvent implements EventHandler {
@3214626
public ResourceResolverFactory rrFactory;
@9944223
public void handleEvent(Event event) {
// do something here...
}
}