Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion Application.cfc - order of execution

I need a reality check - and hopefully an explanation (if my reality is wrong).

The way the CF application framework evaluates things is this (my understanding) - request is passed to cfserver

  • cf finds an application.cfm or cfc (based on traversing rules)

  • application.cfc executes (if found)

  • the THIS scope is set (a series of application specific vars can be set here but

some are required - such as "applicationTimeout" - then a series of events takes place -and methods fired if needed.

-- onApplicationStart()

----onSessionStart()

------onRequestStart()

etc.

so my questions

1) The THIS settings happens on EVERY page request - before anything else?

2) If I set an application variable, in onApplicationStart() - it is available in any process that happens after that - AND should persist in memory for the length of applicationTimeout() - correct?

3) so if I do something like this...

if ( isdefined("application.myvar" ) { this.something = application.myvar; }

it SHOULD work on any page request after the initial request that started the application scope.

however it doesn't appear to do so.

my reason for asking is this - there are some interesting application lever settings that need to be set in the THIS scope... a few of them could be 'intensive' (at least form the perspective of executing on EVERY request - so I want to do them only ONCE, set a structure in persistent mem, and then have those available as THIS.

am I making some wrong assumptions?

thx

like image 235
j-p Avatar asked Aug 13 '12 14:08

j-p


1 Answers

The ColdFusion Application.cfc documentation has this tidbit of knowledge:

When a request executes, ColdFusion runs the CFC methods in the following order:

  1. onApplicationStart (if not run before for this application)
  2. onSessionStart (if not run before for this session)
  3. onRequestStart
  4. onRequest/onCFCRequest
  5. onRequestEnd

The onApplicationEnd, onSessionEnd, and onError CFCs are triggered by specific events.

The overall request order has (at least) two more steps.

0: execute all code in cfcomponent that isn't in a cffunction
0.5: run the equivalent of the cfapplication tag for creating the Application

As such the answers to your questions are:

  1. If you're setting those variables in step 0, then yes.
  2. Correct.
  3. That depends on where you're setting the variable. If the values that you are trying to change are listed on the Application variables documentation page for Application.cfc then they must be in step 0. Setting them elsewhere will update the this scope, but will not take effect in step 0.5.
like image 116
nosilleg Avatar answered Nov 13 '22 07:11

nosilleg