Adobe COLDFUSION 9 Manual page 325

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
By placing the code that sets all of the related session variables in a single
get set together. In other words, setting all of the variables becomes an atomic, or single, operation. It is like a database
transaction, where everything in the transaction happens, or nothing happens. In this example, the order details for
the first order all get set, and then they are replaced with the details from the second order.
For more examples of using locking in applications, see
Using the cflock tag with write-once variables
You need not use
when you read a variable or call a user-defined function name in the Session, Application,
cflock
or Server scope if it is set in only one place in the application, and is only read (or called, for a UDF) everywhere else.
Such data is called write-once. If you set an Application or Session scope variable in Application.cfm and never set it
on any other pages, lock the code that sets the variable, but do not have to lock code on other pages that reads the
variable's value. If you set the variable in the corresponding start method in Application.cfc (for example,
for Application scope variables), you do not have to lock the code that sets the variable.
onApplicationStart
However, although leaving code that uses write-once data unlocked can improve application performance, it also has
risks. Ensure that the variables are written only once. For example, ensure that the variable is not rewritten if the user
refreshes the browser or clicks a back button. Also, it can be difficult to ensure that you, or future developers, do not
later set the variable in more than one place in the application.
Using the cflock tag
The
tag ensures that concurrently executing requests do not run the same section of code simultaneously and
cflock
thus manipulate shared data structures, files, or CFX tags inconsistently. It is important to remember that
protects code sections that access or set data, not the variables themselves.
You protect access to code by surrounding it in a
<cflock scope="Application" timeout="10" type="Exclusive">
<cfif not IsDefined("Application.number")>
<cfset Application.number = 1>
</cfif>
</cflock>
Lock types
The
tag offers two modes of locking, specified by the
cflock
Exclusive locks (the default lock type)
code inside the tag while a request has an exclusive lock.
Enclose all code that creates or modifies session, application, or server variables in exclusive
Allow multiple requests to execute concurrently if no exclusive locks with the same scope or name are
Read-only locks
executing. No requests can run code inside the tag while a request has an exclusive lock.
Enclose code that only reads or tests session, application, or server variables in read-only
read-only lock by setting the
<cflock scope="Application" timeout="10" type="readOnly">
<cfif IsDefined("Application.dailyMessage")>
<cfoutput>#Application.dailyMessage#<br></cfoutput>
</cfif>
</cflock>
"Examples of
cflock
Allow only one request to process the locked code. No other requests can run
attribute in the
type="readOnly"
Last updated 8/5/2010
tag, you ensure that all the variables
cflock
cflock" on page 324.
tag; for example:
attribute:
type
tag, for example:
cflock
cflock
tags.
cflock
tags. You specify a
cflock
320

Advertisement

Table of Contents
loading

Table of Contents