Ok,

Let me say that I use CFC's in session, but the only time that I do this is
when I am calling a webservice or CFJsonService with Dojo or Ajax. And there
is a very good reason for me to do this.

Sticking a CFC into session is no different to not sticking it into any
scope, it will still go through memory just as easily. The only difference
with a session is that if it is a singleton it does not go through the
memory as quickly, garbage collection can be slow at times.

Anyway here is the reason why one would use a CFC in a session scope,
regardless of whether or not it is a webservice or not.

In my case, I have an object that holds booking details for a user. Now I
could each and everytime recreate that object when the user requests it, but
I need to hold certain information until the user is finished with it, and a
user can only have one booking open at a time then there is no problem. But
in case they did then I could have a bookingHandler that could pull the open
bookings out.

Anyway the point is there are times when it is more convinient to hold it in
the session scope, because it is tied to one user. Now I could be smart and
make the bookingHandler be user aware and store it in the application scope,
but either way there is no problem.

Now, as far as the original question goes.

The rules of race conditions need to apply, so basically this translates to
the fact that any read does not need to be locked. But any write to a
variable MUST be locked. Unless you can guarantee 100% that there will be no
race conditions.

So the solution would be something like this in my eyes.

<cfset session.bookingObject = CreateObject(....) />
<cfset session.setBookingNumber(...) />
 <cfset session.getBookingNumber() />

In my bookingObject I would have this

<cffunction name="getBookingNumber">
 <cfreturn variables.bookingNumber />
</cffunction>

<cffunction name="setBookingNumber">
 <cfargument name="bookingNumber" ..... />
 <cflock .....>
  <cfset variables.bookingNumber = Arguments.bookingNumber />
 </cflock>
</cffunction>

As you can see, by me putting the cflock inside the object, I am making sure
that the programmer doesn;t need to worry about all that extra code on the
outside, but on the same token it stops any race conditions from happening
as well.

HTH

Andrew Scott
Senior Coldfusion Developer
Aegeon Pty. Ltd.
www.aegeon.com.au




On 4/7/07, Robertson-Ravo, Neil (RX) <[EMAIL PROTECTED]>
wrote:
>
> Key is still RAM consumption.  If you open say 1000 user sessions, it's a
> RAM killer. I fail to see how any system/framework could advocate
> duplication of components across such a shared scope.  Be interesting to
> see
> if it is actually required or a programmatic necessity or a misuse.
>
>
>
>
>
>
>
>
>
>
> "This e-mail is from Reed Exhibitions (Gateway House, 28 The Quadrant,
> Richmond, Surrey, TW9 1DN, United Kingdom), a division of Reed Business,
> Registered in England, Number 678540.  It contains information which is
> confidential and may also be privileged.  It is for the exclusive use of
> the
> intended recipient(s).  If you are not the intended recipient(s) please
> note
> that any form of distribution, copying or use of this communication or the
> information in it is strictly prohibited and may be unlawful.  If you have
> received this communication in error please return it to the sender or
> call
> our switchboard on +44 (0) 20 89107910.  The opinions expressed within
> this
> communication are not necessarily those expressed by Reed Exhibitions."
> Visit our website at http://www.reedexpo.com
>
> -----Original Message-----
> From: Brad Wood
> To: CF-Talk
> Sent: Fri Apr 06 20:25:54 2007
> Subject: RE: Using CFCs in session scope - need cflock help
>
> To play devils advocate...
> Because, then you wouldn't be encapsulating your data within the object.
>
> -----Original Message-----
> From: Robertson-Ravo, Neil (RX)
> [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 06, 2007 2:18 PM
> To: CF-Talk
> Subject: Re: Using CFCs in session scope - need cflock help
>
> But this userbean.cfc is the same CFC for all yes? I mean, same code,
> same
> interface? If so, then why create it multiple times when only the *data*
> passed is session specific.
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:274728
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