> Isaac, > What's the benefit that CFMX offers in the Application > scope?
> Calvin There were issues involving using unlocked shared scope variables prior to CFMX asside from race conditions (data corruption in memory). In MX locking only needs to be done on shared scope variables for the purpose of handling race conditions, so you don't have to worry so much about making sure that every access of an application scope variable is locked. I still use locking routines in my applications which cover both race conditions and ensure that all shared scope variables are locked, partly for backward compatibility and partly because hosting providers have the ability (although very very few do) to require locking of shared scope variables via the CF administrator. As a matter of fact, here are a couple templates I use to access shared scope vars (sorry for the line wrap guys). This template allows me to access all my shared scopes and know they're properly locked without having to continually write out <cflock>. It also handles all the associative array (structure) syntax so that I can simply pass a dot-delimited string and know that it will set or get the appropriate value even if the string contains hyphens and other non-variablename safe characters. SYNTAX: to check for the existance of and set default for an application variable you would use something like this: <cf_cache action="get" variable="[EMAIL PROTECTED]" default="#arraynew(2)#" return="myarray"> CACHE.CFM <cfsilent> <cfparam name="attributes.action" type="string"> <cfparam name="attributes.variable" type="string"> <cfparam name="attributes.scope" type="string" default="CALLER"> <cfparam name="attributes.return" type="string" default="tObject"> <cfparam name="attributes.timeout" type="numeric" default="30"> <cfset attributes.variable = listtoarray(attributes.variable,".")> <cfif not listfind("session,server,application",attributes.variable[1])> <cfset arrayprepend(attributes.variable,"application")></cfif> <cfset attributes.cachescope = attributes.variable[1]> <cfset attributes.varlen = arraylen(attributes.variable)> <cfswitch expression="#attributes.action#"> <cfcase value="get"> <cfset variables.self = false> <cflock scope="#attributes.cachescope#" type="readonly" timeout="#attributes.timeout#"> <cfset variables.scope = evaluate(attributes.cachescope)> <cfloop index="x" from="2" to="#attributes.varlen#"> <cfif not isstruct(variables.scope) or not structkeyexists(variables.scope,attributes.variable[x])><cfbreak></cfif> <cfset variables.scope = structfind(variables.scope,attributes.variable[x])> <cfif x is attributes.varlen><cfset variables.self = duplicate(variables.scope)></cfif> </cfloop> </cflock> <cfif isboolean(variables.self) and variables.self is false and structkeyexists(attributes,"default")> <cfset variables.self = attributes.default> <cfmodule template="cache.cfm" action="set" objectdata="#attributes.default#" variable="#arraytolist(attributes.variable,'.')#"> </cfif> <cfset variables.returnvar = variables.self> <cfinclude template="return.cfm"> </cfcase> <cfcase value="set"> <cfparam name="attributes.objectdata"> <cfparam name="attributes.timestamp" type="boolean" default="true"> <cfif attributes.timestamp and isstruct(attributes.objectdata)> <cfset attributes.objectdata.tapstoragetime = now()></cfif> <cfset variables.objectdata = duplicate(attributes.objectdata)> <cfset variables.element = attributes.variable[attributes.varlen]> <cflock scope="#attributes.cachescope#" type="EXCLUSIVE" timeout="#attributes.timeout#"> <cfset variables.scope = evaluate(attributes.cachescope)> <cfloop index="x" from="2" to="#decrementvalue(attributes.varlen)#"> <cfif not structkeyexists(variables.scope,attributes.variable[x])> <cfset structinsert(variables.scope,attributes.variable[x],structnew(), true)></cfif> <cfset variables.scope = structfind(variables.scope,attributes.variable[x])> </cfloop> <cfset structinsert(variables.scope,attributes.variable[attributes.varle n],variables.objectdata,true)> </cflock> <cfparam name="attributes.refresh" type="boolean" default="false"> </cfcase> <cfcase value="delete"> <cfset variables.found = true> <cflock scope="#attributes.cachescope#" type="EXCLUSIVE" timeout="#attributes.timeout#"> <cfset variables.scope = evaluate(attributes.cachescope)> <cfloop index="x" from="2" to="#decrementvalue(attributes.varlen)#"> <cfif not isstruct(variables.scope) or not structkeyexists(variables.scope,attributes.variable[x])> <cfset variables.found = false><cfbreak></cfif> <cfset variables.scope = structfind(variables.scope,attributes.variable[x])> </cfloop><cfif variables.found> <cfset structdelete(variables.scope,attributes.variable[attributes.varlen])></cfif> </cflock> </cfcase> <cfcase value="clear"> <cflock scope="#attributes.cachescope#" type="EXCLUSIVE" timeout="#attributes.timeout#"> <cfset variables.scope = evaluate(attributes.cachescope)> <cfloop index="x" from="2" to="#attributes.varlen#"> <cfif not isstruct(variables.scope) or not structkeyexists(variables.scope,attributes.variable[x])><cfbreak></cfif> <cfset variables.scope = structfind(variables.scope,attributes.variable[x])> <cfif x is attributes.varlen><cfset structclear(variables.scope)></cfif> </cfloop> </cflock> </cfcase> <cfdefaultcase> <cfset variables.self = false> <cflock scope="#attributes.cachescope#" type="READONLY" timeout="#attributes.timeout#"> <cfset variables.scope = evaluate(attributes.cachescope)> <cfloop index="x" from="2" to="#attributes.varlen#"> <cfif not isstruct(variables.scope) or not structkeyexists(variables.scope,attributes.variable[x])><cfbreak></cfif> <cfset variables.scope = structfind(variables.scope,attributes.variable[x])><cfif x is attributes.varlen> <cfset variables.self = evaluate("#attributes.action#(variables.scope)")></cfif> </cfloop> </cflock> <cfset variables.returnvar = variables.self> <cfinclude template="return.cfm"> </cfdefaultcase> </cfswitch> </cfsilent> RETURN.CFM <cfsilent> <cfparam name="attributes.scope" type="string" default="CALLER"> <cfparam name="attributes.return" type="string" default=""> <cfparam name="variables.returnvar" default=""> <cfif len(trim(attributes.return))> <cfswitch expression="#listfirst(attributes.scope,'.')#"> <cfcase value="session,application,server" delimiters=","> <cfmodule template="#request.tapi.cache()#" action="set" variable="#attributes.scope#.#attributes.return#" objectdata="#variables.returnvar#"> </cfcase> <cfdefaultcase> <cfset setvariable("#attributes.scope#.#attributes.return#",variables.returnvar)> </cfdefaultcase> </cfswitch> </cfif> </cfsilent> > <cf_snipalot /> >> You'll be needlessly accessing the application scope >> anyway. The > application >> scope should really only be used for data which might >> change periodically >> based on time of day, administrative interraction (i.e. >> "this feature is >> currently unavailable due to maintenance"), or to refresh >> a cacheing >> routine, etc. Data which is set, static and required on >> every page should > be >> set solely in the request scope, unless you're running >> CFMX and planning > to >> access it directly from the application scope -- which I >> prefer not to do >> because imho there's no real benefit over using the >> request scope while >> there are definite advantages to using the request scope >> if you end up >> needing backward compatibility for CF 5. >> >> hth >> >> >> s. isaac dealey 954-776-0046 >> >> new epoch http://www.turnkey.to >> >> lead architect, tapestry cms http://products.turnkey.to >> >> tapestry api is opensource http://www.turnkey.to/tapi >> >> certified advanced coldfusion 5 developer >> http://www.macromedia.com/v1/handlers/index.cfm?ID=21816 >> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > ~~~~~~~~~~~| > Archives: > http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 > Subscription: http://www.houseoffusion.com/cf_lists/index. > cfm?method=subscribe&forumid=4 > FAQ: http://www.thenetprofits.co.uk/coldfusion/faq > Get the mailserver that powers this list at > http://www.coolfusion.com > Unsubscribe: http://www.houseoffusion.com/cf_lists/uns > ubscribe.cfm?user=633.558.4 s. isaac dealey 954-776-0046 new epoch http://www.turnkey.to lead architect, tapestry cms http://products.turnkey.to tapestry api is opensource http://www.turnkey.to/tapi certified advanced coldfusion 5 developer http://www.macromedia.com/v1/handlers/index.cfm?ID=21816 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Get the mailserver that powers this list at http://www.coolfusion.com Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4