I have seen all of the warnings to make sure to use <cflock> around any of
the in memory variable types in a CF application. I hear that every access
of a session, or application variable should have <cflock> around it, or I
could enable automatic locking on the server which will exact a performance
hit though. Is there a different kind of lock I should use when reading a
session or app variable than when I am writing to one of these variables?
How about when I create a session or app variable?

Here is a bit of code from a shoppingcart that I have written. It's is the
addtocart()... Where should the cflocks go? Since I am not totally sure
about cflock and it's uses I currently just cflock all of this tag,
essentially single threading the entire function. This probably isn't too
bad, since performance isn't a big requirement for the sites that I am using
this code on. In my never ending quest for that extra millisecond though,
understanding cflock is the next step.

<cfif  isDefined("attributes.price") and isDefined("attributes.quantity")
and isDefined("attributes.itemcode")>

<cfif NOT isDefined("session.cart")>
 <cfset session.cart = structnew()>
</cfif>

<cfset temp = ListToArray('#attributes.price#,#attributes.quantity#')>

<cfif NOT structKeyExists(session.cart, attributes.itemcode)>
 <cfset rs = structInsert(session.cart, attributes.itemcode, temp)>
<cfelse>

 <cfset temp[2] = attributes.quantity>
 <cfset rs = structUpdate(session.cart, attributes.itemcode, temp)>
</cfif>

</cfif>

jon


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to