Lucee Tag Reference
<cflock>
Provides two types of locks to ensure the integrity of shared data: Exclusive lock and Read-only
lock. An exclusive lock single-threads access to the CFML constructs in its body. Single-threaded access
implies that the body of the tag can be executed by at most one request at a time. A request executing
inside a cflock tag has an "exclusive lock" on the tag. No other requests can start executing inside the
tag while a request has an exclusive lock. Lucee issues exclusive locks on a first-come, first-served
basis. A read-only lock allows multiple requests to access the CFML constructs inside its body concurrently.
Therefore, read-only locks should be used only when the shared data is read only and not modified. If another
request already has an exclusive lock on the shared data, the request waits for the exclusive lock to be
released.
Body
This tag must have a body.
Example
<cflock [name=string] [result=string] [scope=string] [throwontimeout=boolean] [timeout=object] [type=string]> </cflock>
This tag is also supported within cfscript
<cfscript> lock [name=string] [result=string] [scope=string] [throwontimeout=boolean] [timeout=object] [type=string] { [...] } </cfscript>
Attributes
The attributes for this tag are fixed. Except for the following attributes no other attributes are allowed.
Name | Type | Required | Description |
---|---|---|---|
name | string | No | Specifies the name of the lock. Only one request can execute inside a cflock tag with a given name. Therefore, providing the name attribute allows for synchronizing access to resources from different parts of an application. Lock names are global to a server. They are shared between applications and user sessions, but not across clustered servers. This attribute is mutually exclusive with the scope attribute. Therefore, do not specify the scope attribute and the name attribute in a tag. The value of name cannot be an empty string. |
result | string | No | Specifies a name for the structure in which cflock returns the statusCode and ExecutionTime variables. Default variable is is "cflock". |
scope | string | No | Specifies the scope as one of the following: Application, Server, or Session. This attribute is mutually exclusive with the name attribute. |
throwontimeout | boolean | No | Yes or No. Specifies how timeout conditions are handled. If the value is Yes, an exception is generated to provide notification of the timeout. If the value is No, execution continues past the cfclock tag. Default is Yes. |
timeout | any | No | Specifies the maximum amount of time, in seconds, to wait to obtain a lock. If a lock can be obtained within the specified period, execution continues inside the body of the tag. Otherwise, the behavior depends on the value of the throwOnTimeout attribute. If not set, the remaining request timeout is used instead. |
type | string | No | readOnly or Exclusive. Specifies the type of lock: read-only or exclusive. Default is Exclusive. A read-only lock allows more than one request to read shared data. An exclusive lock allows only one request to read or write to shared data. |