Adobe COLDFUSION 9 Manual page 308

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
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, 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 multi-threaded 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 changes 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
Using variables in clustered systems
Because memory variables are stored in memory, they are not available to all servers in a cluster. As a result, you
generally do not use Session, Application, or Server scope variables in clustered environment. However, use these
scope variables in a clustered system in the following circumstances:
• If the clustering system supports "sticky" sessions, in which the clustering system ensures that each user session
remains on a single server. In this case, you can use session variables as you would on a single server.
• You can use Application and Server scope variables in a cluster for write-once variables that are consistently set, for
example, from a database.
To use client variables on a clustered system, store the variables as cookies or in a database that is available to all servers.
If you use database storage, on one server only, select the Purge Data for Clients that Remain Unvisited option on the
Client Variables, Add/Edit Client Store page in the Server Settings area in the ColdFusion Administrator.
Managing the client state
Because the web is a stateless system, each connection that a browser makes to a web server is unique to the web server.
However, many applications must keep track of users as they move through the pages within the application. This is
the definition of client state management.
ColdFusion provides tools to maintain the client state by seamlessly tracking variables associated with a browser as the
user moves from page to page within the application. You can use these variables in place of other methods for tracking
client state, such as URL parameters, hidden form fields, and HTTP cookies.
"Locking code with
cflock" on page 318.
Last updated 8/5/2010
303

Advertisement

Table of Contents
loading

Table of Contents