Search code examples
aemdispatcher

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


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?


Solution

  • 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.