Expand my Community achievements bar.

Clear dispatcher cache when resource only exist in AEM Dispatcher

Avatar

Community Advisor

We have a scenario where we have some dynamic page. These pages have been handled by AEM dispatcher( and getting cached in AEM dispatcher. These pages do not exist in AEM instance.

As a next step, we have to clear the cache for these pages using replication API. The page URL contains a selector in the URL, e.g. /content/abc/xyz/test.sample.html

 

We have written code for the same and we could see below error.

*WARN* [sling-default-2] com.adobe.cq.cloudconfig.core.impl.ConfigurationReplicationEventHandler Resource [/content/abc/xyz/test.sample.html] not found for ReplicationAction

 

Since the resource do not exist, we are getting this error.

 

How to clear cache for these pages using replication API when these page do not exist in AEM instance but do exist in the dispatcher?

14 Replies

Avatar

Community Advisor

@Rohit_Utreja 

 

How about using TTL on these pages. Then they would be flushed periodically.


Aanchal Sikka

Avatar

Community Advisor

@aanchal-sikka 

Yes, that is an option but it is not aligned with the use case.

we have to clear the cache with selector in the URL. URLs can be as follows.

/content/abc/xyz/test.sample1.html

/content/abc/xyz/test.sample2.html

/content/abc/xyz/test.sample3.html

 

Now, all of these page cache need to be cleared only when there are some changes in the content. We will get to know about these content changes from an API.
Hence, if we use TTL, it will be applicable to all URLs, not to a specific URL.

 

To conclude this, we can't use TTL.

Avatar

Community Advisor

I think you can try some of below options:

[1]. You can use a CURL command to flush the specific resource, something like this:

 

 curl -H “CQ-Action: Flush” -H “CQ-Handle: /content/my/page/path” -H “CQ-Path:/content/my/page/path” -H “Content-Length: 0″ -H “Content-Type: application/octet-stream” 

 

[2]. You can create a custom servlet to flush the cache, something like this: https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/page-invalid...

[3]. You can manually delete the entry from the dispatcher server, (you could wrap this into a script and invoked from somewhere else) something like this:

 

#the path where the cache is stored
rm -rf /mnt/var/html/www/content/my/page/path

 

 



Esteban Bustamante

Avatar

Community Advisor

We have tried this.
Since the resource,/content/abc/xyz/test.sample.html doesn't exist, we get the warning com.adobe.cq.cloudconfig.core.impl.ConfigurationReplicationEventHandler Resource [/content/abc/xyz/test.sample.html] not found for ReplicationAction.

 

Page cache has not been cleared and we are still getting the old copy. 

Avatar

Community Advisor

The problem is that the replication API is meant to work with a resource, if you don't have a resource you cannot use this API. You should explore my 3rd option in that case.



Esteban Bustamante

Avatar

Community Advisor

Since it is a AEMaaCS, we can't do that as well.
is there any other option for this?

Avatar

Community Advisor

So I want to fully understand your scenario, Do you actually have the resource(page) "/content/abc/xyz/test.html", and want to remove all its selector-based variations?, if so, Did you try something like the one below? (Use CQ-ACTION : DELETE) 

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-flush-selector-base...



Esteban Bustamante

Avatar

Community Advisor

Yes, even we tried the same using replication API. but it is not working. Cache in the dispatcher is not getting cleared or as mentioned in the thread above, that file will be deleted when we execute the code. It is not happening
snippet looks something like this.

 

ReplicationOptions options = new ReplicationOptions();
options.setSynchronous(true);
options.setFilter(agent -> agent.getId().equals("flush"));
replicator.replicate(resourceResolver.adaptTo(Session.class), ReplicationActionType.DELETE, paths, options);

Avatar

Community Advisor

@Rohit_Utreja 

 

Try using the ACS Commons Dispatcher Flush rules in the lower environment to see if it works in your usecase:

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

I would setup a flush rule as follows and try:

/content/abc/xyz/test(.*) = /content/abc/xyz/test

Avatar

Community Advisor

ACS commons dispatcher flush is not compatible with AEMaaCS, hence can't use this.

Avatar

Employee Advisor

What do you mean with "these pages do not exist in AEM"? How do you get them created then?

Avatar

Community Advisor

We are using dispatcher rewrite rules for convert a url into selector based url.
for example, end user is accessing the url https://www.abc.com/sample/, 
dispatcher is redirecting it to /content/abc/xyz/test.sample.html

Now, the cache has been created under root with path /content/abc/xyz/test.sample.html

We are performing certain operations based on the selector in the URL.

Now, the question is, how to clear the cache of these pages based on the selector (these selector are changing as well)?

Avatar

Employee Advisor

Then it depends how your content structure looks like.

 

Assuming that  www.abc.com/sample is rewritten into /content/abc/xyz/test.sample.html, then I hope that you have a path /content/abc/xyz/test in your repository; everything else would make this situation much more complex.

 

So in that case invalidating that path should be sufficient. But if you have more pages like this and rewrite /sample1 to /sample100 the same way, they will be invalidated as well.

But there is no way around that.

 

 

Avatar

Community Advisor

All the selector pages should flush automatically with publishing of main page. You might check the 

/statfileslevel and 

 /invalidate

section of your dispatcher configuration which works for doing the auto invalidation of the resource if certain node is activated/deactivated.

 

check this blog.  
https://www.axamit.com/blog/adobe/dispatcher-4#:~:text=You%20may%20use%20the%20%2Fstatfileslevel,to%....