Skip to main content
Inspiring
July 1, 2010
Question

CFLOCK Component/Struct

  • July 1, 2010
  • 2 replies
  • 408 views

Hello,

First, I am totally lost when it comes to CFLOCK.

Second, I am worried about some code I wrote... The code, when invoked, passes an ID to a Component which returns a structure of user data. I am worried that if this component is invoked from two different places on the site at the same time, that user data could get mixed up.

What is the best way to protect against this from happening? As I mentioned, I am totally lost when it comes to CFLOCK and I am not comfortable adding it to my pages without understanding what it does. Which is why I don't have a CFLOCK tag around this code.

Thanks

Josh

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    July 8, 2010

    In my opinion you've set it up quite well. What you could use to distinguish between users is the session scope.

    There is no mixing up of user data in the following example:

    <cfset id = 23>

    <cfset userObj = createobject("component", "user")>

    <cfset session.userData = userObj.getUserData(id)>

    User.cfc

    ========

    <cfcomponent>
        <cffunction name="getUserData" returntype="struct">
            <cfargument name="userID">
            <!--- etc. etc.  --->
            <cfreturn data>
        </cffunction>
    </cfcomponent>

    Inspiring
    July 1, 2010

    if you use cflock on a piece of code, it can't be run again until it finishes this time.  For what you are doing, I wouldn't use it either.