<cfif NOT
StructKeyExists(application,"mySingleton")>
<cflock name="mySingletonLock" Timeout="10" THROWONTIMEOUT="No" Type="Exclusive">
<cfif NOT StructKeyExists(application,"mySingleton")>
<cfset application.mySingleton = CreateObject('component','Singleton').init(....)>
</cfif>
</cflock>
</cfif>
<cflock name="mySingletonLock" Timeout="10" THROWONTIMEOUT="No" Type="Exclusive">
<cfif NOT StructKeyExists(application,"mySingleton")>
<cfset application.mySingleton = CreateObject('component','Singleton').init(....)>
</cfif>
</cflock>
</cfif>
Does
that help? The lock is necessary to be absolutely sure, because there's a very
small time lag between the moment a request passes thru the first cfif and the
moment application.mySingleton is created.
n.
:)
---------------------------------------------------------------Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Peter H
Sent: Thursday, May 12, 2005 3:16 PM
To: [email protected]
Subject: [CFCDev] Singleton / Factory request----------------------------------------------------------Hi guys,I'm trying to build a Singleton / Factory but seemed to have got myself a little tangled up. Here's what I'm trying to do.1) Have a factory component that is responsible for creating all of my other components by name.2) Make this factory a singleton so that it's only created once and stored in application scope.I've heard people talk about this on the board and was hoping someone would post be able to post some code for me to look at.Cheers, Pete (aka lad4bear)
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
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 words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
