Expand my Community achievements bar.

How to clear the dipatcher cache without activating the page for single page as a workflow.

Avatar

Level 3

I created the workflow and added the process step. in the java class am trying to clear the cache using the below piece of code.

 
 
            //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("http://"+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();

https://docs.adobe.com/docs/en/cq/5-6/deploying/dispatcher/page_invalidate.html

 

This is not working from author instance and not using the above code in servlet its just normal java class. please let me know what will b the best way.

we need to provide the workflow to user to clear the particular page cache(need not be the current page).

Thanks in advance.

3 Replies

Avatar

Community Advisor

Hi Ramyan,

Facing similar task, solution was not to use raw REST post but to create a dummy path and flush it using the:

com.day.cq.replication.Replicator API

This seemed like the most feasible approach.

Thanks,

Peter

Avatar

Level 3

Hi Thanks for the response. Can you explain the approach with some more details.