Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application vs request scope in CFC

Status
Not open for further replies.

stevelionbird

Programmer
Jul 21, 2006
21
US
Ok, I've having trouble deciding what would be the most efficient way to have variables accessible everywhere in an application.

I'm using an Application.cfc with cfmx 7, so my original idea (to make a deep copy of an application-scoped struct with duplicate() on each request to a request-scoped variable) doesn't work. The reason is that whenever I try to duplicate a structure in the application scope, coldfusion throws an error about duplicating components.

My question is what is the best way to keep my application (or I should say site-wide) variables in a scope that I don't have to constantly lock to access.

My current thinking is that I should avoid the application scope altogether and just make sure I make good use of the onRequestStart method to ensure everything I need is always set in the request scope. This does however seem like an ugly hack.

Any tips?

Thanks,
Steve
 
Here is a quick workaround, but I'm still not sure if there is a better way since this loop, albeit a small one, runs on each request:
Code:
<cfif not isDefined("request.app")>
    <cfset request.app = structNew()>
</cfif>
<cflock type="readonly" scope="Application" timeout="10">
    <cfloop collection="#application#" item="key">
        <cfif isValid("any",application[key])>
            <cfset request.app[key] = application[key]>
        </cfif>
    </cfloop>
</cflock>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top