You could use the server scope -- it still breaks encapsulation to some
extent, so it's not really a "best practice", but since you KNOW the server
scope will always exist (unlike Application and Session scope) it strikes me
as less of a violation of encapsulation.

Alternatively, if you want to make things cleaner you could make a separate
component that hold configuration info and cache that instance, then feed it
to your component when you init().




> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Bryan F. Hogan
> Sent: Thursday, October 16, 2003 8:24 AM
> To: [EMAIL PROTECTED]
> Subject: [CFCDev] Initialize only once
>
>
> Good morning all, I have the following code that reads from a
> configuration
> file. I only want this function to read once and then cache the
> data within
> the component. Outside of caching the component itself is there a way to
> cache the data within the component?
>
> <cfset init()>
>
> <cffunction name="init" access="public" returntype="struct"
> output="false">
>
>       <cfset var initReturn=structNew()>
>       <cfset var objXML=''>
>       <cfset var idx=1>
>
>       <cffile action="read" charset="utf-8"
>               file="#ReplaceNoCase(getCurrentTemplatePath(),
> ListLast(getCurrentTemplatePath(), '\'), 'config.xml')#"
>               variable="objXML">
>
>       <cfset objXML=XMLParse(objXML)>
>       <cfset objXML=XMLSearch(objXML, '/config/')>
>
>       <cfloop from="1" to="#ArrayLen(objXML[1].XMLChildren)#" index="idx">
>               <cfset
> initReturn[objXML[1].XMLChildren[idx].XMLName]=objXML[1].XMLChildr
> en[idx].XM
> LText>
>       </cfloop>
>
>       <cfreturn initReturn>
> </cffunction>
>
>
> ----------------------------------------------------------
> 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]
>

----------------------------------------------------------
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]

Reply via email to