Sam,

See Sean's note. The User object is a stateful object, meant to be used in a situation where only one user is going to be using it at a time... so it's perfect for the session scope. In effect, a record object IS a per-user value. User.getUserID() returns a number, related to one row in a table... so there can only be one user's data in that record at a time. By definition that makes it unsharable between users...

If you're going to use it in the controller or the application scope you're going to have to deal with locking to make sure that and bear the brunt of fun-making, insults, beratement, belittlement, and abuse. ;) Kidding... even locking may not help you. Hehe... it can be made to work, yes, but it's far from ideal. Put the reactor factory in the controller's variables scope and call getSessionFacade().set("User",getReactorFactory().createRecord("User")) instead. Then you don't have to protect User 12314 from seeing the data from User 15345.

And without proper locking in place (which will drastically degrade the performance of your application under load), it's not just bad form... it means that one user's data might get written to another user's record if there's any overlap between 2 or more requests. It's downright dangerous. Collisions may be rare, but they're devastating when they happen.

Laterz,
J


------------------------------------------------

Jared C. Rypka-Hauer

Continuum Media Group LLC

http://www.web-relevant.com

Member, Team Macromedia - ColdFusion


"That which does not kill me makes me stranger." - Yonah Schmeidler


On Apr 18, 2006, at 7:23 PM, Sam Clement wrote:

It's an important distinction because when you have a MG controller with a record set into it's variables scope, everyone accessing it will see the same values in that record... so, for example, if you did <cfset arguments.event.setValue("userId",variables.userRecord.getUserID())>, every single person hitting that page will see the same value, not the right one.

Hmm... I generally use a session facade if I want to output per-user variables.  Maybe I'm being dense but I just don't see the problem with putting a record object in the application scope and just re-initialising it when it is accessed (though I can kind of see that it might be bad form). 

Jared, thanks for taking the time for try and explain.  I'll go over what you're saying again and see if it becomes clearer to me.

Cheers,

Sam

Reply via email to