Andrew and folks,

AFAIK it's not strictly necessary lock Application when we're reading
it. But I preferer do it for the sake of server and app stability. You
never know...
For a few times I used Application scope to define global variables
(only locking it on writing) without problems, even over high traffic.
But after a time I didn't see any speed improvement using it instead of
local or request variables. Application variables are stored on the
server memory so in teory it's available instantaneously to any tamplate
but it didn't see real benefits on using it.

Anyway, maybe if you have just a few global variables (3 or 5) doesn't
matter the scope you use, the time spent on the creation and reading of
these variables won't affect the general template time processing.

After reading the comments I think request is the best because I use a
lot of CFMODULE and also Custom Tags.

Thanks all!
Alex

-----Original Message-----
From: Andrew Scott [mailto:[EMAIL PROTECTED]] 
Sent: quarta-feira, 26 de junho de 2002 11:36
To: CF-Talk
Subject: RE: What is the best variable scope?


Shared variables such as application and session should be locked,
however the lock really only needs to be there on a write. Writing to a
shared variable can cause the system to hang or enter a state of
confusion, hence the locking of the variable.

However although recommended to lock all reads and writes, I personally
have never done it on a read of said such variables. It is also very
safe to do the following...

<cflock>
 <cfset application.test = "Test">
 <cfoutput>Hello</cfoutput>
</cflock>

All it means is that while this bit of code is being run, nobody else
can access this bit of code until this process has released the lock. If
2 applications write to a variable at the exact same time (rare, but
very possible) CF can enter a state of deadlock and will require the
server to be restarted.

For more information on this, consult the manual about the attributes
scope and type that allow the variable to be read only or exclusive and
to define the type of variable it is. For example is it an application,
server or even session scope.

But the point is well within what has been discussed many times on this
list, should we or should we lock reading of variables. Like I said I
don't when reading them, and have never had any problems (touch wood)
with this method.

But there are many reasons why one should use application scope
variables, for example to determine how many people are actually logged
into a membership system as a good example.
 


-----Original Message-----
From: Shawn Regan [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, 27 June 2002 12:18 AM
To: CF-Talk
Subject: RE: What is the best variable scope?

Why do you need to lock it?

Shawn Regan



______________________________________________________________________
Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to