22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta<br />

About client and session variables<br />

<strong>ColdFusion</strong> provides two tools for managing the client state: client variables and session<br />

variables. Both types of variables are associated with a specific client, but you manage and use<br />

them differently, as described in the following table:<br />

Variable type Description<br />

Client Data is saved as cookies, database entries, or Registry entries. Data is<br />

saved between server restarts, but is initially accessed and saved more<br />

slowly than data stored in memory.<br />

Each type of data storage has its own time-out period. You can specify the<br />

database and Registry data time-outs in <strong>ColdFusion</strong> Administrator.<br />

<strong>ColdFusion</strong> sets Cookie client variables to expire after approximately 10<br />

years.<br />

Data is stored on a per-user and per-application basis. For example, if you<br />

store client variables as cookies, the user has a separate cookie for each<br />

<strong>ColdFusion</strong> application provided by a server.<br />

Client variables must be simple variables, such as numbers, dates, or<br />

strings. They cannot be arrays, structures, query objects, or other objects.<br />

Client variable names can include periods. For example, My.ClientVar is a<br />

valid name for a simple client variable. Avoid such names, however, to<br />

ensure code clarity.<br />

You do not have to prefix client variables with the scope name when you<br />

reference them, However, if you do not use the Client prefix, you might<br />

unintentionally refer to a variable with the same name in another scope.<br />

Using the prefix also optimizes performance and increases program<br />

clarity.<br />

You do not lock code that uses client variables.<br />

You can use client variables that are stored in cookies or a common<br />

database in clustered systems.<br />

Session Data is stored in memory so it is accessed quickly.<br />

Data is lost when the client browser is inactive for a time-out period. You<br />

specify the time-out in the <strong>ColdFusion</strong> Administrator, the Application.cfc<br />

initialization code, or Application.cfm.<br />

As with client variables, data is available to a single client and application<br />

only.<br />

Variables can store any <strong>ColdFusion</strong> data type.<br />

You must prefix all variable names with the Session scope name.<br />

Lock code that uses session variables to prevent race conditions.<br />

You can use session variables in clustered systems only if the systems<br />

support “sticky” sessions, where a session is limited to a single server.<br />

404 Using Persistent Data and Locking

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!