Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > Using UDFs effectively > Specifying the scope of a function Selecting a function scope PreviousNext

Selecting a function scope

The following table describes the advantages and disadvantages of scopes that you might considering using for your functions:

Scope

Considerations

Application

Makes the function available across all invocations of the application. Unlike with functions defined in Application.cfm or included from other ColdFusion pages, all pages use the same in-memory copy of the function. Using an Application scope function can save memory and the processing required to define a function multiple times. However, Application scope functions have the following limitations:

  • You must lock the code that puts the function name in the Application scope, but you do not have to lock code that calls the function.
  • Application scope functions can cause processing bottlenecks because the server can only execute one copy of the function at a time. All requests that require the function must wait their turn.

Request

Makes the function available for the life of the current HTTP request, including in all custom tags and nested custom tags. This scope is useful if a function is used in a page and in the custom tags it calls, or in nested custom tags.

Server

Makes the function available to all pages on a single server. In most cases, this scope is not a good choice because in clustered systems, it only makes the function available on a single server, and all code that uses the function must be inside a cflock block.

Session

Makes the function available to all pages during the current user session. This scope has no significant advantages over the Application scope.


Contents > Developing ColdFusion MX Applications > Writing and Calling User-Defined Functions > Using UDFs effectively > Specifying the scope of a function Selecting a function scope PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.