[thelist] ColdFusion Application Variables

Buffington, Michael michael.buffington at office.xerox.com
Thu Feb 6 10:28:39 CST 2003


I think your process of creating variables in the Application scope and then appending them to the request scope is one step too many (and with your code, is creating a pointer).

I'd suggest creating the structures in the request scope, and making sure that the code that does so is executed on every request.

The request scope, as you probably know, is available to everything: custom tags, UDFs, included files, etc.

The application scope is also available, but to create variables within it, you must exclusively lock it. To read variables, you must readonly lock it.

So, with all that said, creating all of your variables in the request scope is a lot more efficient, and easier to access. The scope isn't shared, so there's not risk of corruption, and no need to lock.

<tip type="ColdFusion" author="Michael Buffington">
Use the Duplicate() function in ColdFusion to perform a "deep copy" of a variable or complex structure or query. The function makes a copy of the structure or variable with no reference to the original variable, avoiding any "pointer" issues.
</tip>

-----Original Message-----
From: Seth Bienek [mailto:evolt.list at sethbienek.com]
Sent: Thursday, February 06, 2003 7:41 AM
To: thelist at lists.evolt.org
Subject: RE: [thelist] ColdFusion Application Variables




> -----Original Message-----
-snip-
> I'm wondering if there is a performance increase by using
> Applicaiton variables versus creating a structure for each
> page to hold the variables.  Is there an even better way to
> do it?  These variables are the same across the whole
> site/application and won't be changed often (if it all).  It
> seems to me that it would be more work for CF to recreate the
> structure on each page than it would be to hold the
> Application variable and call it each time.
-snip-

I have an addendum to this question; kind of along the same lines.  I've
been storing application variables on app initialization, then have the
following code in my Application.cfm:

<cflock scope="application" type="readonly" timeout="5">
	<cfset StructAppend(request, application)>
</cflock>

Basically, copying the app variables into the request scope.  This
eliminates the locking issues, but at what cost?  Is CF creating a
pointer to the application variables, or is it actually copying the
Application structure's contents into the request structure, and is this
a performance-affecting technique?  If anyone knows offhand, I'd be much
obliged; otherwise, I suppose some testing is in order.

Thanks,

Seth

--
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !



More information about the thelist mailing list