|
|
> <!--- DO I NEED TO USE CFLOCK HERE???? --->
No, in either situation.
Ask yourself... what would the ramifications be of two requests hitting
that line of code "simultaneously"? The end result is that both of them
are setting the variable to the same static value... so that's what's going
to end up happening: variables.instance.cacheInterval is going to be set to
300 (or 5) in each situation.
You could well with to lock a block of code which - if called
simultaneously via more than one request - could act on shared storage
space (server, application or session data) differently and incorrectly
than is intended.
eg:
<!--- application bootstrap process --->
<cfif not structKeyExists(application, isInitialised and not
application.isInitialised>
<!--- initialisation process, whatever it is --->
<cfif allOK>
<cfset application.isInitialised = true>
<cfelse>
<cfset application.isInitialised = false>
</cfif>
</cfif>
So a sequence of events could be (say the user is hitting the site with two
different browsers):
REQUEST1: application.isInitialised doesn't exist
REQUEST1: starts the init process
REQUEST2: application.isInitialised STILL doesn't exist
REQUEST2: starts the init process *again*
REQUEST1: sets the application.isInitialised value
REQUEST2: sets the application.isInitialised value
Obviously one does not want two request running the initialisation code.
note this is a slightly contrived example, as if one has an
OnApplicationStart() method, then it will only run once, and that's where
one would have the init code, but it demonstrates the issue.
Google "race condition". Those are the situations in which one needs to
lock blocks of code.
--
Adam
|
|