Highlighted

Can you help me work cache activation?

chung_yonge1684

19-10-2018

Hello Everyone,

I have implemented executeCurlCommand using curl command to delete / activate cache.

Now cache deletion works well.

But cache activation doesn't work.

I have no idea why.

If you are availabe, can you help me work cache activation?

Here are my source code to delete / activate cache using curl command.

-------------------------------------------------------------------

public static final String DISPATCHER_HEADER_CQ_ACTION = "CQ-Action";

public static final String DISPATCHER_HEADER_CQ_HANDLE = "CQ-Handle";
public static final String DISPATCHER_HEADER_CQ_PATH = "CQ-Path";
public static final String DISPATCHER_HEADER_CONTENT_LENGTH = "Content-Length";
public static final String DISPATCHER_HEADER_CONTENT_TYPE = "Content-Type";
public static final String DISPATCHER_HEADER_CONTENT_TYPE_VALUE = "application/octet-stream";

public static void execute(BundleContext bundleContext, Event event) {

        if (bundleContext != null && event != null) {

            final ServiceReference rrServiceReference = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());

            final ResourceResolverFactory resolverFactory = (ResourceResolverFactory) bundleContext.getService(rrServiceReference);

            final ResourceResolver resolver = AdminService.getResourceResolver(resolverFactory);

            final ReplicationAction replicationAction = ReplicationEvent.fromEvent(event).getReplicationAction();

            final ReplicationActionType replicationActionType = replicationAction.getType();

            if (replicationActionType.equals(ReplicationActionType.ACTIVATE)) {

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DELETE);

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.ACTIVATE);

            } else if (replicationActionType.equals(ReplicationActionType.DEACTIVATE) ||

                    replicationActionType.equals(ReplicationActionType.DELETE)) {

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DELETE);

            }

        }

}

private static void executeCurlCommand(List<String> dispatchers, String[] paths, ReplicationActionType methodType) {

        for (String path : paths) {

            for (String dispatcher : dispatchers) {

                String[] command = {

                        "curl",

                        "-H", Constants.DISPATCHER_HEADER_CQ_ACTION + ": " + methodType.getName(),

                        "-H", Constants.DISPATCHER_HEADER_CQ_HANDLE + ": " + path,

                        "-H", Constants.DISPATCHER_HEADER_CQ_PATH   + ": " + path,

                        "-H", Constants.DISPATCHER_HEADER_CONTENT_LENGTH + ": " + "0",

                        "-H", Constants.DISPATCHER_HEADER_CONTENT_TYPE + ": " + Constants.DISPATCHER_HEADER_CONTENT_TYPE_VALUE ,

                        dispatcher

                };

                try

                {

                    ProcessBuilder process = new ProcessBuilder(command);

                    process.start();

                }

                catch (IOException e) {

                    log.error(e.getMessage(), e);

                }

            }

        }

}

Replies

Highlighted

PuzanovsP

MVP

21-10-2018

Dear Chung,

Following piece of source code might be relevant for you[0]

Chris Millar@Adobe has done stunning work at implementing Dispatcher functions, have a look, they are perfect and elegant.

[0] slick-2/DispatcherServiceImpl.java at master · auniverseaway/slick-2 · GitHub

Regards,

Peter

Highlighted

chung_yonge1684

22-10-2018

Dear Peter

the source code doesn't work in my local.

I am trying to implement how to invalidate Dispatcher Cache from the Authoring Environment.

When I publish page from the Authoring Environment, cache deletes successfully on dispatcher.

But cache doesn't activate on dispatcher.

Regards

Chung Yong.

Highlighted

PuzanovsP

MVP

22-10-2018

Dear Chung,

My cincere apologies that the code did not work for you,

Also, have a look at following article[0], also remember that AEM has already done all the hard work for you and they provide Replicator API for your needs[1].

[0] Invalidating Cached Pages From AEM

[1] Replicator ("The Adobe AEM Quickstart and Web Application.")

Regards,

Peter

Highlighted

chung_yonge1684

22-10-2018

Dear Peter

I have already read the information([0] Invalidating Cached Pages From AEM) last week.

I don't think there is the way to activate cache in information([1] Replicator ("The Adobe AEM Quickstart and Web Application."))

I can not understand why cache deletion works well and cache activation doesn't work on dispatcher in my source code.

Regards

Chung Yong.

Highlighted

PuzanovsP

MVP

22-10-2018

Dear Chung,

Normally, from AEM -> Dispatcher, via the API documented above, we update .stat file to let Dispatcher know that the files lower down in the tree need to be re-rendered from the server defined to it as renderer.

We do not Activate any content from Author to Dispatcher, we only tell Dispatcher, which files need to be updated from the Content Publishing Server.

Happy to be corrected here through )

Regards,

Peter

Highlighted

chung_yonge1684

22-10-2018

Dear Peter

But from AEM -> Dispatcher, via the API documented above I have already deleted any content from Author to Dispatcher.

Can I delete any content from Author to Dispatcher only?

Can I not activate any content from Author to Dispatcher?

Regards

Chung Yong.

Highlighted

PuzanovsP

MVP

22-10-2018

Dear Chung,

Yes, you can only delete from Author to Dispatcher (as of current Dispatcher module version 4.3.1 and apache 2.4).

You can't activate content e.g. POST data from Author to Dispatcher.

Only Dispatcher can GET data from Author, after it receives notification that .stat file has updated or no content is cached.

Some AEM customers solve activation by switching from Dispatcher to Varnish or CDN which provide functionality to prepare content for customer and thus avoid additional fetch request delay.

Regards,

Peter

Highlighted

chung_yonge1684

23-10-2018

Dear Peter

I found the below one yesterday.

Cannot re-cache files through invalidate.cache

https://forums.adobe.com/thread/1219628

He had the same problem with me 5 years ago.

He had the same version Apache Server 2.2 on Windows with me.

But He upgraded From Apache Server 2.2 to Apache Server 2.4.

He changed the operating system from Windows to Linux because Apache Server 2.4 for dispatcher didn't support windows.

Download Dispatcher Web Server Modules

https://www.adobeaemcloud.com/content/companies/public/adobe/dispatcher/dispatcher.html

And He solved the problem.

I wonder if I have to change my operating system from Windows to Linux in order to install Apache Server 2.4 for dispatcher like him

Highlighted

PuzanovsP

MVP

23-10-2018

Dear Chung,

You might be spot on here.

Please test it and report to community whether this is the issue.

Regards,

Peter