ColdFusion and Application.cfc gotcha

I wanted to post this quick post to highlight the fact that it can be confusing to some how the Application.cfc works, with this I mean in how it sets application variables.

In the days before Application.cfc we used to use cfapplication in Application.cfm, in those days with Application.cfm the setting or tag cfapplication continued to set the application settings.

Today I was almost convinced that the way Application.cfc worked, until I recalled my many hours of debugging and changing of these settings in some Applications that I have worked on. And it ended up reconfirming my way of thinking, and I wondered how many other people out there might be in the same boat that this person tried to convince me that I was wrong.

So the rule of thumb is that anything that you use in the Application.cfc that is set with the this scope, like name timeout settings etc. Is the same as if it was the old days, it runs and is set every page request.

This is something that I was almost convinced was not the case until I remembered the times of my debugging etc., so if you ever find yourself in this position you need to remember one thing.

If you need to use the this scope to set something up for the Application scope, it is run and set at every page request.


ColdFusion and Application.cfc gotcha - http://cfbloggers.org/?c=41130 Apr 27, 2010

  • Ken Auenson's Gravatar Andy,

    While you imply it in your post and it may seem obvious, I just wanted to clarify for new CF users who may find this via a google search...

    This applies only to variables that are being set outside of any function within the application.cfc.  If you are setting this variables inside one of the functions within application.cfc, then those variables are only being set when that function is executed.

    For that matter, *any* code that is outside of the functions in application.cfc will be run on every page request.
    # Posted By Ken Auenson | 4/27/10 1:27 PM
  • Andrew Scott's Gravatar Very good point, should have clarified that some more.
    # Posted By Andrew Scott | 4/27/10 2:10 PM