Created
October 10, 2019 18:52
-
-
Save prestonmcgowan/61bcd2bae5d7a489f5195058b0fe4780 to your computer and use it in GitHub Desktop.
Cache variables in a session's cache per MarkLogic E-Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
declare function local:get-value($name as xs:string) { | |
(: Make sure the $name is valid :) | |
if (fn:string-length($name) le 0) then () | |
else | |
(: Attempt to retrieve the value from the session variable :) | |
if (xdmp:get-session-field($name)) then | |
text{ "Cached:",xdmp:get-session-field($name)} | |
else | |
(: Save the header value into the session variable :) | |
let $rqst-value := xdmp:get-request-header($name) | |
return | |
if (fn:string-length($rqst-value) le 0) then () | |
else | |
text{ "Header:",xdmp:set-session-field($name, $rqst-value)} | |
}; | |
<names> { | |
for $x in xdmp:get-request-header-names() | |
return <x name="{$x}">{local:get-value($x)}</x> | |
}</names> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment