Delete a variable #2

This is a follow-up to
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=coldfusion&qid=20006528

I get this error if I use tvanek's code with a NAME attribute:

Attribute set validation error in tag CFLOCK

The tag has an invalid attribute combination: the most likely attribute combinations are

Required attributes: 'SCOPE,TIMEOUT'. Optional attributes: 'THROWONTIMEOUT,TYPE'.
Required attributes: 'TIMEOUT'. Optional attributes: 'NAME,THROWONTIMEOUT,TYPE'.
Other possible combination is
(No suggestions)

Here's the code:

<cfset session.fighter = 1>
<CFLOCK NAME="test_lock" TYPE="EXCLUSIVE" scope="SESSION" TIMEOUT="60">
<cfset foo = structDelete(session, "fighter")>
</cflock>

I've never used <CFLOCK> before, so I decided to read up on it.  I've got the "Mastering ColdFusion" book by Arman Danesh (good book).  He recommends to use the NAME attribute (page 479):

"Although [the NAME] attribute is not required, it is hightly recommended that you use it."
...
"If two CFLOCK tags share the same name, then only one tag can be accessed at a time.  If you do not name them in this manner, you could run into read/write access problems.
For example, if application.test is set in one template, but no CFLOCK name is specified, ColdFusion will automatically generate a random name to lock the code.  But say that in a second template someone is trying to read application.test and the lock around that code has no NAME attribute as well.  ColdFusion will generate a unique name, but it will not be the same name that locks the write access to application.test in the girst template.  So you could have one user writing to the variable and another user reading the variable at the same time.  This can cause the server to hang, or incorrect data to be  to the variable."

So, if it's so highly recommended to use the NAME attribute, how come I get this "invalid attribute combination" error?  What's the use of locking and area of code using a randomly unique name?  It'll still allows two clients access to the same data causing possible data corruption.

What's the proper syntax?
LVL 2
cpopinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cheekycjCommented:
Your code should look like this:
<CFLOCK TYPE="EXCLUSIVE" scope="SESSION" TIMEOUT="30">
<cfset session.fighter = 1>
<cfset foo = structDelete(session, "fighter")>
</cflock>

When cflocking session vars you don't need to specify the name.

The only time you want to use the NAME option is when you are reading/writing files (then you don't need to specify the scope)

<CFLOCK TYPE="EXCLUSIVE" TIMEOUT="30" NAME="#filename#">
<CFFILE ACTION="READ" FILE="/files/#filename#" variable="filereadin">
</cflock>

HTH,
CJ
tvanekCommented:
SCOPE is a newer attribute to ColdFusion.  In previous versions, you had to use NAME.  Yes, you should be using SCOPE="session" for your locks and NOT specifiying a name for them.

And as CJ pointed out, you can use named locks for things like file operations.  For a simple file read, you wouldn't need a lock.  However, if you have any other ColdFusion code that writes or updates that file, it's a good idea to put a lock around both the WRITE/APPEND action and the READ action with the same lock name.  Here's an example.

-----[ writefile.cfm - creates the file from the database ]-----
<cflock name="lockCustomersFile" type="exclusive" timeout="30">
     <cffile action="write" file="c:\www\customers.txt" output="#qCustomers.customerInfo#">
</cflock>

-----[ readfile.cfm - reads the file ]-----
<cflock name="lockCustomersFile" type="readonly" timeout="30">
     <cffile action="read" file="c:\www\customers.txt" variable="#qCustomers.customerInfo#">
</cflock>

The read only requires a "readonly" lock.  This will allow other requests for the file read to run at the same time, which will not cause problems for you.  However, the exclusive lock will not let any other ColdFusion code with a lock named "lockCustomersFile" run until it completes.  You obviously don't want someone reading the file while it's being written.

Hope that makes sense,

Tyson Vanek
Senior Consultant
< a l l a i r e > Corporation

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tvanekCommented:
Sorry, first line of my previous comment should read like this:

SCOPE is a newer attribute to ColdFusion's CFLOCK tag.

:-)

-Tyson
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

cheekycjCommented:
You may want to lock a file when reading so no one updates it when you try to read it.

CJ
tvanekCommented:
Any progress here???

-Tyson
cpopinAuthor Commented:
Sorry for the delay.  Blame a combo of ExpertSexChange and my workload...
cpopinAuthor Commented:
Last time I added this comment, and quite a bit since then, EE keeps giving me a 500 error and a Java stack trace.  If you'll be patient with me, I'll be patient with EE and grade this question.

Thanks,

-=- cpopin
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11459298.html
http://www.experts-exchange.com/questions/Q.20010196.html
http://www.experts-exchange.com/questions/Q.20075528.html
http://www.experts-exchange.com/questions/Q.20075531.html
http://www.experts-exchange.com/questions/Q.20084574.html
http://www.experts-exchange.com/questions/Q.20133957.html
http://www.experts-exchange.com/questions/Q.20137511.html
http://www.experts-exchange.com/questions/Q.20170250.html
http://www.experts-exchange.com/questions/Q.20253165.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20242991.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
cheekycjCommented:
IMHO, split btw tvanek and me.

CJ
cpopinAuthor Commented:
I'll give you both 50 points, tvanek here and cheekyci at
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=coldfusion&qid=20284557

Thanks,

-=- cpopin
cheekycjCommented:
Thank you for coming back and taking care of this question.

CJ
MoondancerCommented:
I also thank you.  :)
cpopinAuthor Commented:
Sorry for the delay, but I must admit it was due to the lack of response from the EE server earlier on.  I haven't been using it lately that much, but it seems to be much more responsive.  Guess that's why their sentinal have been deployed.  I've been getting e-mails to clean up my posted questions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.