Using Application Variables

Application variables require an application name be associated with them and are always scoped within that application name.

Unlike client and session variables, however, application variables do not require that a client name (client ID) be associated with them. Thus, they are available to any clients that specify the same application name.

The name you establish in the CFAPPLICATION tag is accessible elsewhere in the application by using the Application.ApplicationName variable. For example, you would use this variable in the CFLOCK tag to restrict access to application variables to one request at a time.

Storing application data in application variables

Application variables are designed to store application-level data. They are a convenient place to store information that all pages of your application might need no matter who (what client) is running that application. Using application variables, an application could initialize itself, say, when the first user hit any page of that application. This information could then remain available indefinitely to all subsequent hits of any pages of that application, by all users, thereby avoiding the overhead of repeated initialization.

Because the data stored in application variables is available to all pages of an application and remains available until ColdFusion Server is shut down, application variables are very convenient. However, because all clients running an application see the same set of application variables, they are not useful for client-specific information. To target variables for specific clients, use session variables.

Application variable time-outs

Application variables have a specific lifetime, and this lifetime defines an "application." For example, when you access an application variable inside a specific application, the variable returns a value because your request occurs on a page declared in the CFAPPLICATION tag to be part of a single application.

The default time-out period for application variables is two days. In the Variables page of the ColdFusion Administrator, you can define time-out values for application and session variables. See Administering ColdFusion Server for more information.

You can set the time-out period for application variables within a specific application (thereby overriding the default setting in the ColdFusion Administrator) by using the APPLICATIONTIMEOUT attribute of the CFAPPLICATION tag.

If no clients access the application within the specified time-out period, ColdFusion Server destroys its application variables.