Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes Ezra Parker Dan Wilson John Mason Jason Dean Luis Majano Mark Mandel Brian Kotek Wil Genovese Rob Brooks-Bilson Andy Matthews Simeon Bateman Ray Camden Chris Rockett Joe Bernard Dan Skaggs Byron Raines Barney Boisvert Simon Free Steve 'Cutter' Blades Seth Bienek Katie Bienek Jeff Coughlin

What Happens When I Cache Application.cfc Within The APPLICATION Scope?

By
Published in Comments (1)

Pretty much nothing exciting :) But I wanted to try it to see if stuff would blow up. If nothing else, it proves that a new Application.cfc instance is created for every single page request. This test is super, ultra simple. Here is my Application.cfc ColdFusion component:

<cfcomponent>

	<cfset THIS.Name = "App Cache Test" />
	<cfset THIS.ApplicationTimeout = CreateTimeSpan( 0, 0, 5, 0 ) />

	<!---
		Here, I am creating a unique ID for this Application.cfc
		just to help see if one instance is the same as another.
	--->
	<cfset THIS.ID = CreateUUID() />

	<cffunction
		name="OnRequestStart"
		access="public"
		returntype="boolean"
		output="false">

		<!---
			Param an array in the APPLICATION scope to hold all
			of our App.cfc instances.
		--->
		<cfparam
			name="APPLICATION.Apps"
			type="array"
			default="#ArrayNew( 1 )#"
			/>

		<!---
			Append THIS application.cfc instance to our
			cached array.
		--->
		<cfset ArrayAppend(
			APPLICATION.Apps,
			THIS
			) />

		<cfreturn true />
	</cffunction>

</cfcomponent>

Then, my index.cfm page merely CFDumps out the APPLICATION scope:

<!---
	Dump out the APPLICATION scope. Put in a TOP 10 to
	make sure nothing goes crazy.
--->
<cfdump
	var="#APPLICATION#"
	top="10"
	/>

After running that page a few times, here is what I get:

Application.cfc Caching In APPLICATION Scope

As you can see, nothing exciting going on here. At least it didn't go kabooom!

Want to use code from this post? Check out the license.

Reader Comments

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo