Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Last active May 16, 2018 12:16
Show Gist options
  • Save ableasdale/ed88160d9b384e43fb8320d4f38c127e to your computer and use it in GitHub Desktop.
Save ableasdale/ed88160d9b384e43fb8320d4f38c127e to your computer and use it in GitHub Desktop.
MarkLogic: Clearing the Expanded Tree Cache for all hosts in a cluster
xquery version "1.0-ml";
declare variable $USER as xs:string := "username";
declare variable $PASS as xs:string := "password";
declare variable $HOSTS as xs:unsignedLong+ := for $i in xdmp:groups() return xdmp:group-hosts($i);
declare variable $PORT as xs:unsignedLong := 8002;
declare variable $ENDPOINT as xs:string := "/v1/eval";
declare variable $PAYLOAD as xs:string := xdmp:quote("xquery=xdmp:expanded-tree-cache-clear()");
declare variable $OPTIONS as element() :=
<options xmlns="xdmp:http">
<authentication method="digest">
<username>{$USER}</username>
<password>{$PASS}</password>
</authentication>
<data>{$PAYLOAD}</data>
<headers>
<content-type>application/x-www-form-urlencoded</content-type>
</headers>
</options>;
declare function local:generate-cluster-endpoints() as xs:string* {
for $h in $HOSTS
return "http://" || xdmp:host-name($h) || ":" || $PORT || $ENDPOINT
};
for $endpoint in local:generate-cluster-endpoints() return xdmp:http-post($endpoint, $OPTIONS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment