Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Clear Varnish at the time of page activation in AEM

Avatar

Level 6

Hi Friends,

 I have one situation to clear the varnish pages at the time of CQ5 page activation. 

I am using the httpclient to purge the page in varnish . I am getting correct repsonse 200 Purged but that page is not getting cleared from the varnish. 

Here is the code I am using, Please suggest the changes. Its very very urgent.

org.apache.http.HttpHost host = new HttpHost("IP");

HttpClient client = HttpClientBuilder.create().build();

            BasicHttpRequest purgeRequest = new BasicHttpRequest("PURGE", "URL");
            purgeRequest.setHeader("purgeKey","p0rg3m3!");
            purgeRequest.setHeader("Cache-Control","no-cache");           
            HttpResponse response1= client.execute(host,purgeRequest); 

 

Thanks In Advance :)

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

why don't you use the standard replication mechanism and and just create a custom content builder to create the required payload for the request? Replication already supports HTTP.

Jörg

View solution in original post

2 Replies

Avatar

Administrator

Hi 

I am not an expert at Varnish, all i know it its a middle-ware between Client and Server.

Assuming you know the API for clearing the cache in varnish. To clear it on page activation, you can do:

1. Write a Replication Listener. This will act as a event listener whenever you activate a page/

You can call Varnish API for purging from here.

Reference Link:-  https://helpx.adobe.com/experience-manager/kb/ReplicationListener.html

 

2. Custom workflow on page activation (which will again use replication event listener in it), here also you can all Varnish API for purging.

Reference Link: - http://stackoverflow.com/questions/18864317/start-a-workflow-on-page-activation-without-activating-t...

 

If your question is how to Purge it, then 

1. This will set caching to disabled on the response:

    // Set standard HTTP/1.1 no-cache headers.
    response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");

    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

 

2. Clear Varnish cache for a url

[:$] varnishadm -T 127.0.0.1:6089 ban.url /index.html

Link:- https://linuxacademy.com/blog/linux/how-to-clear-varnish-cache/

 

3. Command-line purging of Varnish caches

Link:- https://robm.me.uk/ops/2014/12/09/command-line-purging-varnish.html

 

Some AEM Varnish Reference links:- 

https://info.varnish-software.com/blog/advanced-cache-invalidation-applied-replacing-adobe-aem-cq5-d...

https://info.varnish-software.com/blog/advanced-cache-invalidation-part2

 

I hope this might help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Correct answer by
Employee Advisor

Hi,

why don't you use the standard replication mechanism and and just create a custom content builder to create the required payload for the request? Replication already supports HTTP.

Jörg