It sounds to me like if the objects are being _assigned_ on each request
that it may be a bug... but make sure you check your application timeout
in your Application.cfc or CFApplication tag (whichever you're using) to
make sure you didn't accidentally assign it a really short timeout of
say a couple seconds that may be causing the application to timeout
between requests. 

However... even if the value already exists in the application and the
cfparam tag behaves correctly, I would say this is probably not the way
you want to create your component objects. It would probably be a lot
better to use the onApplicationStart method of your Application.cfc or
optionally if you don't have one, to use 

<cfif isdefined("application.objects.cms")>
  <cfset application... />
  yadda...
</cfif>

The reason for this may not be immediately obvious from looking at the
tags. The cfparam tag receives all its input _before_ it assigns
anything, so for example, if you were to say: 

<cfparam name="form.x" default="#variables.x#" />

This line will error out if variables.x is undefined, even if form.x
*is* defined. Why? Well, because it doesn't do anything with the input
until it has all the input, so it's looking for the default value before
it checks to see if there's an existing definition. Had I written the
engine I might have written it differently, but... I digress... 

The long and the short of it is that if you use cfparam and put a
CreateObject() call in the default attribute, it's going to create one
every time the param tag executes it, whether it's used of not. So even
if it were retaining your application variables the way you wanted them
to, the server would still be doing a bunch of extra, unnecessary work,
creating new ones on each request.

Now there is an alternative that you may or may not like that allows you
to do basically what you were hoping for and at the same time prevent
the server from creating a whole bunch of components it's not going to
use: 

<cfcomponent displayname="appObjects">
  <cffunction name="init" access="public" output="false">

    <cfinvoke component="security" returnvariable="this.security"
      method="init" authorization="public"
      language="#Left(CGI.HTTP_ACCEPT_LANGUAGE,2)#" />

    <cfset this.util = CreateObject("component","util") />

    <cfinvoke component="db" returnvariable="this.db" method="init" 
      dsn="irama" maxStringLength="25" />

    <cfset this.cms = CreateObject("component","cms").init() />

    <cfreturn this />
  </cffunction>
</cfcomponent>

<cfset application.objects = iif(
  structKeyExists(application,"objects"),
  "application.objects",
  "CreateObject('component','components.appObjects').init()") />

The iif() function unlike the cfparam tag accepts strings as input
instead of the result variables and then determines which one to
evaluate once it's received it's input. So in this case, if
application.objects exists, then the string containing the CreateObject()
code isn't evaluated and it doesn't create that extra object that's
created by the cfparam tag. 

Or you could just: 

<cfif not StructKeyExists(application,"objects")>
  <cfinvoke component="components.appObjects" 
    method="init" returnvariable="application.objects" />
</cfif>

Which is probably what I would do. Heck I might even wrap a named cflock
around that cfif statement just in case because iirc the server doesn't
single-thread the application start. 

hth,
ike

-- 
s. isaac dealey  ^  new epoch
 isn't it time for a change? 
     ph: 503.236.3691

http://onTap.riaforge.org



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:295344
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to