Session data
A Lua module API is provided to allow opaque session data to be set and retrieved from a Lua script.
It is sometimes useful for a Lua script to be able to set state information, and be able to retrieve this information on subsequent HTTP requests. The
Session.setSessionAttribute() and Session.getSessionAttribute() functions can be used to store and retrieve opaque data against the user session. This capability is especially useful if the Lua script requires state information for a user to persist across multiple HTTP requests.
Note: The state information can be accessed only when an authenticated user session is available. Session attributes cannot be accessed from within request triggers, and can be accessed from within preazn triggers only after an authenticated session is established.
Attention: The Lua
Session.setSessionAttribute() function is currently not supported when using the Distributed Session Cache.The following example illustrates how to access session data from a Lua script:
-- If the access identity is not currently available invoke
-- the get_access_id() function to retrieve the access
-- identity and then store this in the session for future
-- use.
access_id = Session.getSessionAttribute("access_id")
if (access_id == nil) then
Session.setSessionAttribute("access_id", get_access_id())
end