Listing 1

function GetObject (txtCFC, blnCached) {
   var scope = SERVER.EXAMPLE;
   var myObject = 0;

   if (blnCached) {
      if (not StructKeyExists(scope, txtCFC)) {
         myObject = CreateObject("component", txtCFC);
         myObject.init();
  scope[txtCFC] = myObject;
      }
      return scope[txtCFC];
   } else {
      myObject = CreateObject("component", txtCFC);
      myObject.init();
      return myObject;
   }
}

objNavigation = GetObject("hotbanana.navigation", true);

Listing 2

<cffunction name="getQuery">
   <cfif not StructKeyExists(this, "myQuery")>
      <cfquery name="this.myQuery" datasource="myDSN">
         SELECT *
         FROM table
      </cfquery>
   </cfif>
   <cfreturn this.myQuery />
</cffunction>

Listing 3

<cfcomponent displayname="example">

   <cffunction name="resetArray">
      <cfset this.array = ArrayNew(1)>
      <cfset this.array[1] = "First Element">
      <cfset this.array[2] = "Second Element">
      <cfset this.array[3] = "Third Element">
   </cffunction>

   <cffunction name="getItemThree">
      <cfset resetArray()>
      <!--- Hope nothing happens to this.array --->
      <cfreturn this.array[3]>
   </cffunction>
</cfcomponent>

Listing 4

<cfcomponent displayname="example">
   <cffunction name="resetArray">
      <cflock name="exampleLock" timeout="10" type="exclusive">
         <cfset this.array = ArrayNew(1)>
         <cfset this.array[1] = "First Element">
         <cfset this.array[2] = "Second Element">
         <cfset this.array[3] = "Third Element">
      </cflock>
   </cffunction>

   <cffunction name="getItemThree">
      <cfset resetArray()>

      <cflock name="exampleLock" timeout="10" type="readonly">
         <cfreturn this.array[3]>
      </cflock>
   </cffunction>
</cfcomponent>