There's an easy technique to avoid excessive locking with any shared
scope (application, server, session) variables.  Rather than locking the
variables all over the place, simply lock them once, make a copy of them
into the "request" scope, and use those.  Here's a code example where
this would save you much locking headache.

<!--- lock session and read name/email address --->
<cflock scope="session" type="readonly" timeout="30">
        <cfset request.session.strFirstName = session.strFirstName>
        <cfset request.session.strLastName = session.strLastName>
        <cfset request.session.strEmail = session.strEmail>
</cflock>

<!--- if the user has an email address in their session --->
<cfif len(trim(request.session.strEmail))>
        <!--- print their name with a link --->
        <cfoutput>
                <a
href="mailto:#request.session.strEmail#";>#request.session.strFirstName#
#request.session.strLastName#</a>
        </cfoutput>
<cfelse>
        <!--- otherwise, just print the name --->
        <cfoutput>
                #request.session.strFirstName#
#request.session.strLastName#
        </cfoutput>
</cfif>

As you can see, by using the copy of the value I made into the request
scope, I now no longer need to lock all the read I did when printing the
user's name and email address.  Of course, if you wanted to change the
value of the session variables, you'd still need to do an exclusive lock
and change the actual session variable.  Changing the
request.session.strEmail in this example would have NO effect on the
actual session.strEmail variable.  It's a best practice to have as
little code as possible between <CFLOCK> tags just as a precaution.  If
you have CFLOCK tags around more than 10 lines of code, you should
re-evaluate and see if there's an easier way to write the same code with
out locking so much of it and still following the best practice of
locking shared scope variables.

Hope this helps,
Tyson

------------------------------------------------
Tyson Vanek, Technical Lead
duoDesign, The eBusiness Architects
Building your business online

847.491.3000 main | [EMAIL PROTECTED]
847.491.3100 fax | www.duodesign.com
847.491.4270 direct | www.chicagoangels.org

Come to our free 2-hour seminar "The eBusiness Squeeze"
http://www.duodesign.com/squeeze/seminar.html


-----Original Message-----
From: Bruce, Rodney [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 06, 2001 6:00 PM
To: CF-Talk
Subject: RE: I don't understand session locking :(


Question here as well

I have done locks when ever I set a Session var.
Do I have to use a lock  when ever I use the var?
i.e:

        <CFLOCK type="readonly" scope="session">
                <CFSET session.bgcolor = "blue">
        </CFLOCK>


<body bgcolor=#session.bgcolor#>

Are you saying I need to place a lock around the <body> tag?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to