Is it possible to recursively flush directories in the CQ5/AEM apache dispatcher?
Asked Answered
D

2

7

I have a dispatcher set up with a fairly deep stats file level due to a particular project in a multi tenancy situation.

What I'm hoping is for a way to be able to recursively flush directories to mimic a more shallow stats file level for the other tenants.

Is there a dispatcher flush command that allows me to explicitly delete a directory of content?

Dominiquedominium answered 25/7, 2014 at 1:14 Comment(0)
V
5

You could achieve this yourself by sending a simple GET request to your dispatcher. The path on the Dispatcher that you need to hit is /dispatcher/invalidate.cache.

The following headers ensure that it's processed correctly:

  • CQ-Action: This can be set to "DELETE" to remove the content. I think "EXPIRE" also works to flag the content as out-of-date, but not remove it physically from the cache.
  • CQ-Handle: This specifies what should be deleted, starting from the root of your cache folder. E.g. "/content/geometrixx", would remove geometrixx and everything under it. "/" would remove everything in the cache.
  • Content-Length & Content-Type: Ensure that the request is handled correctly. As we're not sending a body, the length can be set to 0. Content-Type can be "application/octet-stream" (haven't tried other values).

The final curl command that you would build would then look something like:

curl -v \
-H "CQ-Action: DELETE" \
-H "CQ-Handle:/" \
-H "Content-Length: 0" \
-H "Content-Type: application/octet-stream" \
http://localhost:80/dispatcher/invalidate.cache;

(Where this is removing everything from the cache on a Dispatcher running under localhost on port 80. This backslashes here are optional, just making it easier to read)


You could issue this GET request from any box (subject to your firewall restrictions, etc.), for example, it could come from:

  • your CI build agent
  • a scheduled job in your Publish instance
  • an admin component in your Author instance that takes a given path to flush.
Varve answered 25/7, 2014 at 11:43 Comment(8)
I tried CQ-Handle as "/" to remove everything under cache, but it's not deleting all folders under cache folder, it just deletes the .stat file in cache folder. I am on dispatcher 4.1.9, Apache 2.2, Windows 7. Works fine for a folder ex "/content". Anything specific we have to configure for "/"?Cailean
@Sandeep Kumar, not that I know of — you're sending the CQ-Action: DELETE header too? Does it work on a vanilla install of the same tech stack for you?Varve
@anotherdave, yes I am sending CQ-Action: DELETE header, it works for "/content" perfectly. I am on vanilla installation of AEM 6.1Cailean
@SandeepKumar, unless it's related to folder permissions in Windows on the cache root? I've only worked with Dispatcher on Linux servers, but never needed any amends to get this working, sorry!Varve
@Varve Tested this on a Unix box, it works fine on Unix box, the whole cache folder is getting deleted. Thank you +1. Seems to be some other issue on Windows as there is no permission issue as such. Unix box has Apache 2.4, but I don't think that should be an issue on Windows.Cailean
@Varve There was more discussion done with team, there was a suggestion to not delete cache but mark it stale so that content is available as part of failover. I was trying CQ-Action: EXPIRE. It gave me Unknown action: EXPIRE, flush ignored warning. I tried CQ-Action: Activate also, but its not marking all content as stale. Issue was related to same thread, so posted as comment, let me know if this is fine. I was trying to mark all content stale, not delete.Cailean
@SandeepKumar sorry, not sure what's happening there — both should be valid header values according to the docs. Activate should issue a request to recache the file, so possibly it's not marking as stale of content in Dispatcher & CQ Pub is the same? Not sure thoughVarve
@Varve Content is same on dispatcher and cq pub. Thanks for reply, let me check more on this. If I find something I will update.Cailean
B
0

It's not clear to me the overall picture but IIRC dispatcher flush if flush the entire directory and all of it's subdirectories. The file types that will be flushed depends on your dispatcher configuration.

So if you flush /content/geometrixx the whole site will be flushed. (Please someone correct me if I remember wrongly).

The easiest way to do it is IMHO to re-activate the page that works as root of the area you want to flush. Otherwise you could even develop your own sling servlet that sends appropriate headers to dispatcher

http://docs.adobe.com/docs/en/aem/6-0/deploy/configuring/replication.html#Extended

Other options that always works are the same as the HTTP headers but sent with curl commands or OS processes that deletes the directory from the file system.

I'm not saying the last two are the best as there could be side effects; but they should do the job as well.

Burlie answered 25/7, 2014 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.