On Wednesday, September 25, 2002, at 02:40 , Jay Packer wrote:
> I have some questions regarding the use of application variables that I
> was hoping for some suggestions on.

The best answers depend heavily on which version of CF you're using. CFMX 
requires much less locking than earlier versions.

> First is the issue of locking. If I understand correctly, I'll gain a
> small performance boost if I do my own locking instead of allowing CF to
> automatically lock all READS via the CF administrator.

In CFMX there is no option to auto-lock I believe and, besides, you don't 
need to. Pre-MX, I don't know which is faster.

> Secondly, when
> doing my own locking, what the best way to use variables on the page?
> Instead of putting locks around chunks of code where application (or
> session) variables would be used, I've been reading my variables into
> the local scope at the top of my templates where they're needed, like
> this:

Well, it depends on how often you access them and whether it matters if 
they change during page execution (because some other request changed them)
.

In CFMX, you can just read application.x without locking.

> Also, what's the best way to initialize application variables?

        <cflock name="app_initialize" ...>
                <cfif not isDefined("application.isInitialized")>
                        <!---
                                run your query etc / cfinclude template
                                set all your app variables
                        --->
                        <cfset application.isInitialized = true/>
                </cfif>
        </cflock>

Note the lock *outside* the cfif, not inside it! Otherwise you could get a 
race between two page requests that both executed the if isDefined 
condition and then both decided to run the query.

Note that you need the lock like this even in CFMX because this is about 
race conditions.

> Here's a really important question: In the above case, will all the
> other application variables exist if application.isInitialized is
> defined? (I'm setting them all at the same time on the same template).

If you do it all inside one lock, it will be safe - the timeout on the 
lock will need to exceed the time the initialization code might take.

> To word the question another way, how can I be sure that all my
> application variables exist so that I don't have to "re-set" them every
> time Application.cfm runs.

Once they've been set, they'll remain set.

Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to