User Guide

Table Of Contents
354 Chapter 15: Using Persistent Data and Locking
Enabling session variables in your application
You must also enable session variables in the initialization code of your Application.cfc file or in
the
cfapplication tag in your Application.cfm file.
Do the following in the Application.cfc initialization code, below the
cfcomponent tag, to enable
session variables:
Set This.sessionManagement="Yes".
Set This.name to specify the application's name.
Optionally, set This.sessionTimeout to set an application-specific session time-out value. Use
the
CreateTimeSpan function to specify the number of days, hours, minutes, and seconds for
the time-out.
Do the following in the Application.cfm file to enable session variables:
Set sessionManagement="Yes"
Use the name attribute to specify the application's name.
Optionally, use the sessionTimeout attribute to set an application-specific session time-out
value. Use the
CreateTimeSpan function to specify the number of days, hours, minutes, and
seconds for the time-out.
The following sample code enables session management for the GetLeadApp application and sets
the session variables to time out after a 45-minute period of inactivity:
<cfapplication name="GetLeadApp"
sessionmanagement="Yes"
sessiontimeout=#CreateTimeSpan(0,0,45,0)#>
Storing session data in session variables
Session variables are designed to store session-level data. They are a convenient place to store
information that all pages of your application might need during a user session, such as shopping
cart contents or score counters.
Using session variables, an application can initialize itself with user-specific data the first time a
user accesses one of the applications pages. This information can remain available while that user
continues to use that application. For example, you can retrieve information about a specific users
preferences from a database once, the first time a user accesses any page of an application. This
information remains available throughout that user’s session, thereby avoiding the overhead of
retrieving the preferences repeatedly.