[thelist] Tip revision (was: Doh! question for MySQL)

chris at fuseware.com chris at fuseware.com
Wed Feb 14 14:50:34 CST 2001


walker,

  Variables in the Application, Session, or Server scope are considered
shared.  This means it is possible in a multi-threaded environment for two
users to access these variables at the same time.  If one user is trying to
set the variable while another is trying to read the variable, it will cause
serious problems on your server.

  To avoid this, you should wrap any tags that write to these variables
(such as CFSET or CFPARAM) in exclusive CFLOCKS.  Any other references to
these variables are considered reads, and need to be wrapped in read-only
CFLOCKS.

This is a good reference:

http://www.allaire.com/handlers/index.cfm?ID=17318&Method=Full&Title=ColdFus
ion%20Locking%20Best%20Practices&Cache=False

Hope that helps,

Chris Evans
chris at fuseware.com
http://www.fuseware.com


-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of walker
Sent: Wednesday, February 14, 2001 12:00 PM
To: thelist at lists.evolt.org
Subject: RE: [thelist] Tip revision (was: Doh! question for MySQL)


Hold on!

You've got me all confused Chris-

two assumptions that you've made:
1) locking application variables - why?
2) cfparam exclusively locks application variables?

I don't mean to ask you to explain, but if you could point me somewhere
where I can read up on this...

thanks for the revision!

-w


At 09:51 AM 2/14/2001 -0500, you wrote:
>Good tip, but you need to *always* lock application scoped variables.  And
>since you don't want to exclusively lock a varaible if you can help it,
this
>is one of the few places you don't want to use CFPARAM.
>
>So a modifed version might look like this:
>
><!--- Set a local variable to determine whether we need to load our
>application var --->
><cflock timeout="30" throwontimeout="No" type="READONLY" NAME="GetStates">
>         <CFIF NOT IsDefined("application.states")>
>                 <CFSET GetStates = TRUE>
>         <CFELSE>
>                 <CFSET GetStates = FALSE>
></CFLOCK>
>
><!--- this is to make sure the query only runs once --->
><cfif GetStates>
>         <!--- here is the query --->
>         <cfquery name="get_states" datasource="yourdb">
>         select * from states
>         </cfquery>
>
>         <!--- save the query --->
>         <cflock timeout="30" throwontimeout="No" type="EXCLUSIVE"
> NAME="GetStates">
>                 <cfset application.states=get_states>
>         <CFLOCK
></cfif>
>
>-----Original Message-----
><deletia>
>
><tip type="cold fusion & saved queries" author="walker">
>If you have queries that should only be run once, and don't change for all
>users in your application (like a query that pulls the states for your
>contact form drop down list) - then save the entire query as an application
>variable....
>
>For example:
>in your application.cfm
>
>(initialize the application variable)
><cfparam name="application.initialize" default="0">
>
>(this is to make sure the query only runs once)
><cfif application.initialize is 0>
>
>          (here is the query)
>          <cfquery name="get_states" datasource="yourdb">
>          select * from states
>          </cfquery>
>
>          (save the query)
>          <cfset application.states=get_states>
>
>          <cfset application.initialize=1>
></cfif>
>
>then in your contact form (or elsewhere):
>
><select class="formbody" name="state">
><cfoutput query=application.states>
><option value=#state_id#>#state_name#</option> (where state_id and
>state_name are columns in the states table)
></cfoutput>
></select>
>
>
>This also works with session variables - if you want to save all of the
>information about a user, etc....
>
>For example, after a login has been validated:
>
>          (here is the query)
>          <cfquery name="get_user_info" datasource="yourdb">
>          select * from users where user_id=#user_id#
>          </cfquery>
>
>          (save the query)
>          <cfset session.user=get_user_info>
>
>and then in your application:
>
>You are logged in as: #session.user.username# (username can be swapped with
>any other column in the users table)
>
></tip>
>
>_________________________________________
>walker fenton
>walker at sdproductions.com
>303.722.5473
>
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt !
>
>
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt !

_________________________________________
walker fenton
walker at sdproductions.com
303.722.5473


---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !






More information about the thelist mailing list