318
Chapter 15: Using Persistent Data and Locking
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.
About client and session variables
ColdFusion provides two tools for managing the client state: client variables and session variables.
Both types of variables are associated with a specific client, but you manage and use them
differently, as described in the following table:
Session variables are normally better than client variables for values that need to exist for only a
single browser session. You should reserve client variables for client-specific data, such as client
preferences that you want available for multiple browser sessions.
Variable type
Description
Client
Data is saved as cookies, database entries, or Registry entries. Data is saved
between server restarts, but is initially accessed and saved more slowly than data
stored in memory.
Each type of data storage has its own time-out period. You can specify the
database and Registry data time-outs in ColdFusion MX Administrator.
ColdFusion sets Cookie client variables to expire after approximately 10 years.
Data is stored on a per-user and per-application basis. For example, if you store
client variables as cookies, the user has a separate cookie for each ColdFusion
application provided by a server.
Client variables must be simple variables, such as numbers, dates, or strings.
They cannot be arrays, structures, query objects, or other objects.
Client variable names can include periods. For example, My.ClientVar is a valid
name for a simple client variable. Avoid such names, however, to ensure code
clarity,
You do not have to prefix client variables with the scope name when you
reference them, However, if you do not use the Client prefix, you might
unintentionally refer to a variable with the same name in another scope. Using the
prefix also optimizes performance and increases program clarity.
You do not lock code that uses client variables.
You can use client variables that are stored in cookies or a common database in
clustered systems.
Session
Data is stored in memory so it is accessed quickly.
Data is lost when the client browser is inactive for a time-out period. You specify
the time-out in the ColdFusion MX Administrator and Application.cfm.
As with client variables, data is available to a single client and application only.
Variables can store any ColdFusion data type.
You must prefix all variable names with the Session scope name.
Lock code that uses session variables to ensure data integrity.
You can use session variables in clustered systems only if the systems support
“sticky” sessions, where a session is limited to a single server.
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......