Ask Ben: Simple Data Caching In ColdFusion

<cfcomponent
	output="false"
	hint="Set up the application configuration and handle application-level events.">
 
 
	<!--- Set application settings. --->
	<cfset THIS.Name = "SimpleCacheDemo" />
	<cfset THIS.ApplicationTimeout = CreateTimeSpan( 0, 0, 5, 0 ) />
 
	<!--- Set page request settings. --->
	<cfsetting
		showdebugoutput="false"
		requesttimeout="10"
		/>
 
 
	<cffunction
		name="OnApplicationStart"
		access="public"
		returntype="boolean"
		output="false"
		hint="Handles the application configuration and initialization.">
 
		<!---
			Create a simple data cache instance and persist
			it in the APPLICATION scope.
		--->
		<cfset APPLICATION.Cache = CreateObject(
			"component",
			"SimpleCache"
			).Init()
			/>
 
		<!--- Return out. --->
		<cfreturn true />
	</cffunction>
 
 
	<cffunction
		name="OnRequestStart"
		access="public"
		returntype="boolean"
		output="false"
		hint="Handles pre-page processing of each request.">
 
		<!---
			Check to see if we need to re-initialized
			the application.
		--->
		<cfif StructKeyExists( URL, "reset" )>
 
			<!--- Re-initialized application. --->
			<cfset THIS.OnApplicationStart() />
 
		</cfif>
 
		<!--- Return out. --->
		<cfreturn true />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste