Again, I've had good experiences with this technique...

Here's an example:

<cflock scope="application" type="readonly" timeout="30">
  <cfparam name="url.getappudf" type="boolean"
        default="#yesnoformat(isdeinfed('application.udf'))#">
  <cfif url.getappudf><cfset request.udf =
duplicate(application.udf)></cfif>
</cflock>

<cfif not url.getappudf>
        <cfset request.udf = structnew()>
        <cfinclude template="mylibrary.cfm">
        <cflock scope="application" type="exclusive" timeout="30">
                <cfset application.udf = duplicate(request.udf)>
        </cflock>
</cfif>

Within the mylibrary.cfm file, all my user-defined functions are coppied
into the request.udf structure. This allows me to cache them in the
application scope, which ( and I've never done any load testing on this )
I've heard helps to reduce some of the load for subsequent page requests. I
would expect this to be the case for a lot of things -- for instance, if you
can't use a cached query for something, or if you want more control over the
result-set, you can cache a query by storing it in the application scope and
use something like the syntax above to determine whether the application
should connect to the db for the data. Subsequent page requests will then be
able to retreive the recordset from the copy cached in the application scope
which is almost always faster than connecting to a database.

The reason for the url variable is to allow you ( as the developer ) to
easily refresh the cached data by adding a url variable to the query string
in your browser, although I wouldn't recommend placing it in links or forms
-- users who know about the flag may be apt to over-use it, thus limiting
the usefullness of your caching scheme. Or for that matter, they may not
even be aware of it and simply continually refreshing pages which contain
the flag.


S. Isaac Dealey
Certified Advanced ColdFusion 5 Developer

www.turnkey.to
954-776-0046

> Thanks for the advice, Isaac. One other question, can you see any reason
> why
> it would be bad to set all my application variables in application.cfm and
> then use an if test to prevents further cfsets? What do you think of this
> technique or are there better ones? My colleague and I are having this
> debate currently.

> Rob

> <<<It depends how much data is in your application scope and how much of
> it
> will be relevant on any given page... I'm inclined to think that you won't
> want to shot-gun it quite that much, although you may not have to go too
> much further... Instead of duplicating the entire application scope, try
> and
> figure out what information will be specific to a given request in the
> application.cfm, for instance, if this is an app which requires a login
> and
> user session information is stored in the application scope, you might
> copy
> just the user session structure for the current user and not the whole
> array
> or structure containing all logged in users.

> For the remaining variables, you might loop through the application
> structure and copy only those which are simple values, i.e.

> <cflock scope="application" timeout="30" type="readonly">
>       <cfset request.user = application.user[urltoken]>
>       <cfloop item = "x" collection="application">
>               <cfif issimplevalue(application[x])>
>                       <cfset request[x] = application[x]>
>               </cfif>
>       </cfloop>
> </cflock>

> I've had good luck with a similar application architecture on CF5.

> Isaac
> Certified Advanced ColdFusion 5 Developer
> www.turnkey.to
> 954-776-0046


>>Hi,
>>I'm upgrading from CF 4.0.1 to CF 5 and I have read that
>>locking changed
>>from 4.0 to 4.5. I'm currently using application variables
>>and wanted some
>>thoughts on this:
>>Does anyone see any issues with moving all of my
>>application variables to
>>the request scope in application.cfm using:
>><cflock SCOPE="Application" Timeout="30" Type="Readonly">
>>      <cfset request=duplicate(application)>
>></cflock>

>>So am I correct that this would mean if i had variables
>>application.foo and
>>application.foobar they will then be request.foo and
>>request.foobar?  Would
>>it be wise to set the request variables in another page
>>other than
>>application.cfm since application.cfm is always hit?
>>OR is there a better way to deal with this? Any
>>tips/tricks/advice is
>>appreciated!

______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm
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