User Guide

Table Of Contents
About persistent scope variables 341
ColdFusion persistent variables and ColdFusion structures
All persistent scopes are available as ColdFusion structures. As a result, you can use ColdFusion
structure functions to access and manipulate Client, Session, Application, and Server scope
contents. This chapter does not cover using these functions in detail, but does mention features or
limitations that apply to specific scopes.
Note: Although you can use the StructClear function to clear your data from the Server scope, the
function does not delete the names of the variables, only their values, and it does not delete the
contents of the Server.os and Server.ColdFusion structures. Using the
StructClear function to clear
the Session, or Application scope clears the entire scope, including the built-in variables. Using the
StructClear function to clear the Client scope clears the variables from the server memory, but does
not delete the stored copies of the variables.
ColdFusion persistent variable issues
Variables in the Session, Application, and Server scopes are kept in ColdFusion server memory.
This storage method has several implications:
All variables in these scopes are lost if the server stops running.
Variables in these scopes are not shared by servers in a cluster.
To prevent race conditions and ensure data consistency, lock access to all code that changes
variables in these scopes or reads variables in these scopes with values that can change.
Note: If you use J2EE session management and configure the J2EE server to retain session data
between server restarts, ColdFusion retains session variables between server restarts.
Additionally, you must be careful when using client variables in a server cluster, where an
application can run on multiple servers.
Locking memory variables
Because ColdFusion is a multithreaded system in which multiple requests can share Session,
Application, and Server scope variables, it is possible for two or more requests to try to access and
modify data at the same time. ColdFusion runs in a J2EE environment, which prevents
simultaneous data access, so multiple requests do not cause severe system errors. However, such
requests can result in inconsistent data values, particularly when a page might change more than
one variable.
To prevent data errors with session, application, and server variables, lock code that writes and
reads data in these scopes. For more information, see “Locking code with cflock” on page 360.