Don wrote:
>In sum, it seems applying cflock is part of best practice for both
preCFMX and CFMX.

Yes, it's a part of each but for different reasons.  In CF5 on down, you
lock persistent scopes because if you don't you are taking your
application's life in your hands.  As was said earlier, you can wind up
getting corrupt data in the form of shared session info, a flat-out
crashed CF service, waxy yellow buildup, ingrown toenails etc.  All very
nasty.

In CF5 on down, you *also* locked to prevent race conditions; an
entirely separate circumstance.  A simple example would be an
application variable that increments itself on each individual page hit:

<cflock scope="application" type="exclusive" timeout="10">
<cfset application.sitecounter=application.sitecounter+1>
<cfoutput>
This is page visit number #application.sitecounter# today.
</cfoutput>
</cflock>

You would lock the variable write and read to make sure that the user
saw the accurate page count, and not a number generated by someone else.

In CF 6+, the first of these two cases is no longer an issue, so
anything that was locked before *solely* for the sake of the first case
above no longer needs it.  However, if you upgrade it won't hurt under
all but very extreme circumstances just to leave the locks in, so unless
you have a compelling reason... skip the anguish of recoding.

Further, if you have a race condition that is inconsequential, then you
can also dispense with locking.  Using the example above, you as a
developer would have to ask yourself if you or anyone else really cared
if the display count was off by a tick or two.  If the answer is no,
then you can get rid of that lock as well.

A more real world example would be a datasource name in the application
scope.  Since it's the same globally, it doesn't matter if a race
condition occurs since the value is set only once in a while ... and
even if it wasn't, its the same value no matter what, anyway.  Same deal
with a user session variable value that is only set once per session,
for example after someone logs in.

It feels very naughty to code in a naked

<cfquery datasource="#application.SiteDSN#" name="myItem">
...
</cfquery>

But its not going to hurt anything on MX.

--------------------------------------------
Matt Robertson       [EMAIL PROTECTED]
MSB Designs, Inc.  http://mysecretbase.com
--------------------------------------------
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to