Yes -- instance variables last only as long as the instance does. Thus, if the instance is not cached from request to request the instance vars will not be cached. You will need either put the variables in a shared memory scope (not suggested), put the instance in a shared memory scope (very acceptable), or use some other component/variable in a shared memory scope that you pass to your component when you init().
> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Bryan F. Hogan > Sent: Friday, October 17, 2003 8:03 AM > To: [EMAIL PROTECTED] > Subject: RE: [CFCDev] Initialize only once > > > Thanks for your reply. Setting a global variable in the > constructor area does not work. Every time the CFC is called it seems > to start from scratch. For example; > > <cfset vars=structNew()> > <cfset init()> > > <cfcomponent name="init"> > <cfset var myResult=''> > > <cfif not structKeyExists(vars, 'result')> > <!--- Read from Config File ---> > <cfset vars.result=myResult> > </cfif> > <cfreturn vars.result> > </cfcomponent> > > If I have a DSN value set in the config file to the correct DSN > all works well. When I change this value to an invalid DSN > name on the next call I get the data source could not be found > error. This is telling me that the CFC clears all instance > data after each use. I thought that maybe placing an > isDefined('vars.result') around the <cfset vars=structNew()> would keep > it from resetting the vars structure, but it does not. Again that > tells me that vars.result is not being saved from request > to request. TGIF! :) > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Thomas Chiverton > Sent: Friday, October 17, 2003 5:07 AM > To: [EMAIL PROTECTED] > Subject: Re: [CFCDev] Initialize only once > > > Of the general purpose Memoizer ? Probably not - but it's a well known IT > method that should be easy to implement given a few hours. > As to a one-off: > > <cfcomponent name="AddReals"> > > <cfset vars.result=newArray()> > > <cffunction name="add"> > <cfarg name="a" > <cfarg name="b" > <cfif isDefined('vars.result[a][b]')><cfreturn vars.result[a][b]></cfif> > <cfelse> > //do complicated time consuming math, set thisResult to answer > <cfif isDefined('vars.result[a]')> > <cfset vars.result[a][b]=thisResult> > <cfelse> > <cfset vars.result[a]=newArray()> > <cfset vars.result[a][b]=thisResult> > </cfif> > </cffunction> > </cfcoponent> ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
