Use Case Flush cache for a path in regular interval of time
Solution You can use following command to flush cache
curl -H "CQ-Action:Flush" -H "CQ-Handle: /content/geometrixx/en/toolbar" -H "CQ-Path:/content/geometrixx/en/toolbar" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://dispatcher-server-hostname:port/dispatcher/invalidate.cache
In Newer version of dispatcher try this
curl -H "CQ-Action: DELETE" -H "CQ-Handle:/content/geometrixx/en/toolbar" -H "CQ-Path:/content/geometrixx/en/toolbar" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://dispatcher-server-hostname:port/dispatcher/invalidate.cache
If you see error like
[Thu May 30 09:23:53 2013] [D] [91650(140735211479424)] Found farm <Your FARM>
[Thu May 30 09:23:53 2013] [D] [91650(140735211479424)] checking [/dispatcher/invalidate.cache]
[Thu May 30 09:23:53 2013] [W] [91650(140735211479424)] Flushing rejected from <Something>
That mean you are not in allowed list of client to flush cache. In that case please allow your IP (<SOMETHING>) in above case in allowedClient section of dispatcher.any
/allowedClients
{
/0000
{
/glob "*"
/type "deny"
}
/0001
{
/glob "<Something>"
/type "allow"
}
... More allowed
}
}
Important Note: Make sure that from outside (DMZ may be) no one should be able to run this command. This command should be allowed to run only from some trusted boxes
Thanks Andrew Khoury from Adobe for this information
Solution You can use following command to flush cache
curl -H "CQ-Action:Flush" -H "CQ-Handle: /content/geometrixx/en/toolbar" -H "CQ-Path:/content/geometrixx/en/toolbar" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://dispatcher-server-hostname:port/dispatcher/invalidate.cache
In Newer version of dispatcher try this
curl -H "CQ-Action: DELETE" -H "CQ-Handle:/content/geometrixx/en/toolbar" -H "CQ-Path:/content/geometrixx/en/toolbar" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://dispatcher-server-hostname:port/dispatcher/invalidate.cache
Expected Response: <H1>OK</H1>
If you see error like
[Thu May 30 09:23:53 2013] [D] [91650(140735211479424)] Found farm <Your FARM>
[Thu May 30 09:23:53 2013] [D] [91650(140735211479424)] checking [/dispatcher/invalidate.cache]
[Thu May 30 09:23:53 2013] [W] [91650(140735211479424)] Flushing rejected from <Something>
That mean you are not in allowed list of client to flush cache. In that case please allow your IP (<SOMETHING>) in above case in allowedClient section of dispatcher.any
/allowedClients
{
/0000
{
/glob "*"
/type "deny"
}
/0001
{
/glob "<Something>"
/type "allow"
}
... More allowed
}
}
Important Note: Make sure that from outside (DMZ may be) no one should be able to run this command. This command should be allowed to run only from some trusted boxes
Thanks Andrew Khoury from Adobe for this information
Whats the difference between the CQ-Handle and CQ-Path?
ReplyDeleteWith the header "CQ-Handle" (CQ-Handle: /content/geometrixx/en), the
ReplyDeletedispatcher will delete the following files and directories in its cache and touch stat file:
./content/geometrixx/en.*
./content/geometrixx/en/_jcr_content/
CQ-Path is optional it looks like
Is there anyway that in this curl script we can specify the folder where we want the cache to be flushed? Sometimes we need to make some script, code, css/js files take effect, and would like these folder to be set up in the script.
ReplyDeleteYes. Please see example above. By supplying CQ-Handle and CQ-Path you can specify folder path that want to flush.
DeletedispatcherServerName=localhost
ReplyDeletedispatcherServerPort=80
dispatcherHandle=/etc/designs/offroad
curl -u admin:admin -X POST -H "CQ-Action: Activate" -H "CQ-Handle: $dispatcherHandle" -H "CQ-Path: $dispatcherHandle" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://$dispatcherServerName:$dispatcherServerPort/dispatcher/invalidate.cache
-------------------
I intend to run the above script via cron on the local Apache webserver with dispatcher module.
When you run this, would it pull updated file from publisher or delete the files under $dispatcherHandle? I noticed this is not happening, even the timestamp of the file. But when I tried to rename a file inside it and hit the page that triggers in caching that file, it pulls the updated one from the publisher.
Thanks for your feedback. I just updated blog with new command and some things that you should look if command is not working.
DeleteHow do you setup trusted box in order to run this command externally?
ReplyDeleteHello Saurav,
DeleteYou can use allowedClient property in dispatcher and then allow that IP from where you are running this command. Only IP listed in allowed Client can do dispatcher flush.
Yogesh
I am trying to flush multiple paths. Is it not possible to pass multiple paths in CQ-Handle/Path in cURL. Please let me know.
ReplyDeleteIn Syntax you can not pass multiple path. However you can write a bash script to have multiple path.
DeleteI already have a script but i was looking if there was a way to flush multiple paths at a shot. Anyway thnx...
DeleteCan we unbind/save a configuration using curl?
ReplyDeleteDo you mean change dispatcher configuration ? If yes then yes you can do it using sling post servlet http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html all replication agents are under /etc/replication/
DeleteYogesh
This comment has been removed by the author.
DeleteNope. This is completely unrelated. I would like to unbind or save a configuration in configmgr (/system/console/configmgr) using curl.
DeleteVenkatesh.
Hello Venkat,
DeleteIf this is custom config then I would suggest to use osgi:config to do that and use curl to update that config. If this is OOTB, you can use curl like
curl -u admin:admin 'http://HOST:PORT/system/console/configMgr/PID' --data 'unbind=1'
Yogesh