I know that the right way to use <cflock>is a pretty big topic of conversation on www for cf developers.
Since I am trying to understand this a little better, I have a simple UDF that I created that accepts an array of sessions, and I am wondering if this is the right thing to do, given that it is a simple UDF.
<cffunction name="currentCartQuantity" access="public" returntype="string">
<cfargument name="partnumber" type="numeric" required="yes">
<cfargument name="data" type="array" required="yes">
<cfset var return_data = "0" >
<cflock type="readonly" scope="session" timeout="1">
<cfloop from="1" to="#arrayLen(arguments.data)#" index="idx">
<cfif arguments.data[idx].partnumber IS arguments.partnumber >
<cfset return_data = arguments.data[idx].quantity >
</cfif>
</cfloop>
</cflock>
<cfreturn return_data >
</cffunction>
This is a simple function that takes an array type argument, which is a session variable in the shopping cart. It also takes a numerical value partnumber. Then it searches for an array of structures to find a suitable value.
, , cflock, , , - CF, ColdFusion 8, , CF , .
200 , , cflock?