Ensures the integrity of shared data. Instantiates the
following kinds of locks:

* Exclusive allows single-thread access to the CFML constructs
* Read-only allows multiple requests to access CFML constructs

  <cflock name="lockName" timeout="3">

 lock name="lockName" timeout="3" { }

Attribute Reference

timeout numeric

Maximum length of time, in seconds, to wait to obtain a
lock. If lock is obtained, tag execution continues.
Otherwise, behavior depends on throwOnTimeout attribute

scope string

Lock scope. Mutually exclusive with the name attribute.
Lock name. Only one request in the specified scope can
execute the code within this tag (or within any other
cflock tag with the same lock scope scope) at a time.
  • Application
  • request
  • Server
  • Session

name string

Lock name. Mutually exclusive with the scope attribute.
Only one request can execute the code within a cflock tag
with a given name at a time. Cannot be an empty string.

throwontimeout boolean
Default: true

How timeout conditions are handled.

type string
Default: exclusive

readOnly: lets more than one request read shared data.
exclusive: lets one request read or write shared data.
  • readonly
  • exclusive

result string
Default: cflock

Lucee 4+ Specifies a name for the structure in which cflock returns the statusCode and ExecutionTime variables. Default variable is "cflock".

Sample code using the cflock tag

lock timeout="60" scope="session" type="exclusive" { 
 session.myVar = "Hello"; 

<cflock timeout="60" scope="session" type="exclusive"> 
 <cfset session.myVar = "Hello"> 

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub