User Guide

Table Of Contents
Using UDFs effectively 195
Selecting a function scope
The following table describes the advantages and disadvantages of scopes that you might
considering using for your functions:
Using the Request scope
You can effectively manage functions that are used in application pages and custom tags by doing
the following:
1.
Define the functions on a function definitions page.
2.
On the functions page, assign the functions to the request scope.
3.
Use a cfinclude tag to include the function definition page on the application page, but do
not include it on any custom tag pages.
4.
Always call the functions using the request scope.
This way you only need to include the functions once per request and they are available
throughout the life of the request. For example, create a myFuncs.cfm page that defines your
functions and assigns them to the Request scope using syntax such as the following:
function MyFunc1(Argument1, Argument2)
{ Function definition goes here }
Request.MyFunc1 = MyFunc1
The application page includes the myFuncs.cfm page:
<cfinclude template="myfuncs.cfm">
The application page and all custom tags (and nested custom tags) call the functions as follows:
Request.MyFunc1(Value1, Value2)
Scope Considerations
Application Makes the function available across all invocations of the application. Access to
UDFs in Application scope is multithreaded and you can execute multiple copies
of the UDF at one time.
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.