Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I save myself from CFLOCKING Sessions?

Session Management

Can I save myself from CFLOCKING Sessions?

by  webmigit  Posted    (Edited  )
Before reading this FAQ, I suggest that if you're new to CFLOCK and/or sessions that you read up on them.

CFLOCK in a simple explanation to suit this FAQ sets cold fusion (a language engine that generally handles multiple threads) to a single thread type until the locked process is done or times out. If you use the name attribute of CFLOCK, well then it single threads in a queue all cflocks with that name.. IE 30 different locks may be in your application and if 5 have the same name, then if 2 or more lock instances with the same namese 5 are accessed simultaneously CF handles them on a first come, first serve basis.. But other processes with different lock names can be accessed at the same time. This is to help keep your application running smoothly without corrupting itself.

I was presented with an application that has about 500 calls to session variables in it, and none of them were locked, it was going to be my job to lock every read on a session variable.. But I found that session variables are stored in the memory and client variables (application,cookie,request) are stored on a page by page basis in a basic definition.. so I could, in application.cfm code the following:

Code:
<CFLOCK timeout="30" name="SetGlobalUser" type="Session">
 <CFSET suser = session.username>
</CFLOCK>

By doing it this way, I could call it as suser from anywhere in the application, even custom tags.. by calling #caller.suser#.

Because this was then set as a page variable.. I didn't need to lock and could use it, read from, write to it freely.. I was able to return to the client a fast application with only minutes of work invested, rather than hours as it would have taken by manually putting in every cflock.

I hope you find this useful.

Tony Hicks
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top