Skip to main content
Known Participant
December 18, 2009
Question

the dope on scope

  • December 18, 2009
  • 2 replies
  • 664 views

I've done a bit of research on Cold fusion scopes, but i still am a bit confused.  I'd really appreciate it if somebody corrected my assumptions outlined below.

Server scope is part of CF, it persist based on a setting in CF Admin and is only re-created by re-starting cold fusion at the server level. - based on it's name, it is tied to a single server in a cluster.  so server.whatever is the same for anybody hitting the server.

Application scope is part of CF, it persists based on a setting in CF Admin and is re-created whenever the 'onApplicationStart' function is called in CF.  it is less persistent than server but more persistent than session.  It is also strongly tied to a single server in a cluster.  This is a shared scope variable.  Each different application run on a server has its own set of application variables, therefore this  variable is less persistent than server.  if i have two applications on my server, than i can easily have two different versions of application.whatever

Session Scope is a part of CF, it exists and persists based on a setting in the application.cfc.  When J2EE sessions are used, it persists across servers in a cluster.  Each session in an app can have it's own copy of the variable, therefore it is less persistent than an application variable.

Request Scope is a part of CF.  It's the one i'm having the most trouble understanding ...based on its position in the application.cfc it is less persistent than application, however how many request variables are created? Are they created anew so that your request.whatever and my request.whatever can be different without a problem and thus less persistent than session?  or is it instead more persistent than session but less than application.  If i create an variable in request, and have say five users (each with one session) on my application page at a time, how many request variables couldi have?

Variables scope is a part of CF as well.  any variable, structure, recordset or scope created outside of the above but inside of a page request will exist within variables. These definitely persist only from the start of a page or fuseaction call to the end of it.  variables scope appears to be discarded between say, index.cfm and page1.cfm (in addition, if you and i both call index.cfm, we have two different sets of variables within variables scope where the system is concerned) on a particular site.

I am particularly interested in how exactly request and variables scope are actually different from each other.  i noted that request does NOT appear when i dump variables, nor variables when i dump request

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 19, 2009
    Application scope is... re-created whenever the 'onApplicationStart' function is called in CF

    Just a remark to add to what Dan has said. Coldfusion doesn't recreate the application scope when onApplicationStart is called. The application scope is recreated whenever Coldfusion starts an application. Thus, using Application.cfm, which involves no onApplicationStart call, will also recreate the application scope.

    It is true that, whenever Coldfusion restarts, it calls the onApplicationStart method. However, if you call the method explicitly, ColdFusion wont start the application. It will only reset the application variables that are declared within the method.

    Inspiring
    December 19, 2009

    The request scope pertains to the entire http request.  Therefore, if you request a page that includes another page that calls a custom tag which refers to a udf that invokes a cfc, request scope variables can be used on all those coldfusion files.  I never use them.

    The variables scope pertain only to the page on which they are set, plus any included pages that are called after that variable is set.  I use these all the time.