简体   繁体   中英

xQuery application scope variable?

Is there a way to declare a variable in the application scope. This variable should stay in the memory and serves all the requests without the need to create it for each request. Something like session, but it is not tied to a specific user.

What Im looking for is something similar to php APC cache.

Session fields provide one possibility; another possibility is server fields:

http://docs.marklogic.com/xdmp:set-server-field

A server field is available to all requests for the appserver on the host.

Since this is tagged "marklogic" I will provide a MarkLogic non-standards answer. The standards based answer is 'no' or 'question out of scope' because XQuery doesnt define an 'application scope' ( beyond the excecution of a the top level module's statement -- which in some context could be called 'application scope' )

In MarkLogic there is a supported feature called 'Sessions'; For web applications that coresponds to what is usually called "Session".

Sessions are created by the first call to xdmp:login() (explicitly or implicitly by running in the HTTP Server using a supported authentication). Session 'state' is created on the first write to a session field (explicitly via xdmp:set-session-field, or implicitly in some cases(*)).

https://docs.marklogic.com/xdmp:set-session-field

Session Fields are a map of name (xs:string) to item()* They last as long as the session lasts (see notes on expiration in link above).

Note that Sessions that span multiple HTTP requests require that the client side participate via proper HTTP Cookie handling ( ML server has no ability nor attempts to to track requests after the socket is closed except via the HTTP Cookie mechanism.)

If you are using a modern browser you need to not disable cookies. If you are using a modern Web Client library this will likely be done for you. If you are using one MarkLogics published SDK's (java, node, xcc) it will be done for you. If you are going through a load balancer, Level 3 router, gateway, proxy ... those may need to be configured for "HTTP Session Affinity" (based on the cookies) to guarantee that cookies are passed through unchanged and that the SessionID cookie is mapped to HTTP affinity.(**)

Note: IT devices vary greatly in their capabilities and terminology. What is often called "Session Affinity" may not relate to cookies, or the right cookies. These can often be configured to work correctly but may require custom code or configurations.

(*) Session state can be created implicitly in some cases by creating a multi-statement transaction. (**) https://docs.marklogic.com/guide/node-dev/extensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM