User Guide
238 Chapter 12 Using the Application Framework
5 Unlock the Application scope.
6 Unlock the Session scope.
Note
You can skip any pair of lock/unlock steps in the preceding list if you do not need to
lock a particular scope. For example, you can omit steps 3 and 4 if you do not need to
lock the Server scope.
Examples of cflock
The following examples show how to use cflock in a variety of situations.
Example with Application, Server, and Session variables
This example shows how you can use cflock to guarantee the consistency of data
updates to variables in the Application, Server, and Session scopes.
This example does not handle exceptions that arise if a lock times out. As a result,
users see the default exception error page on lock timeouts.
The following sample code might be part of the Application.cfm file:
<cfapplication name="ETurtle"
sessiontimeout=#createtimespan(0,1,30,0)#
sessionmanagement="yes">
<!--- Initialize the session and application
variables that will be used by E-Turtleneck. Use
the session lock scope for the Session variables. --->
<cflock scope="Session"
timeout="10" type ="Exclusive">
<cfif not isdefined("session.size")>
<cfset session.size = "">
</cfif>
<cfif not isdefined("session.color")>
<cfset session.color = "">
</cfif>
</cflock>
<!--- Use the application lock for the
Application variable. This variable keeps
track of the total number of turtlenecks sold.
use the application lock scope for application variables. --->
<cflock scope="Application"
timeout="10"
type="Exclusive">
<cfif not isdefined("application.number")>
<cfset application.number = 1>