From: <ndi...@us...> - 2002-10-05 00:51:45
|
Update of /cvsroot/modus/org/bacfug/modus/caching In directory usw-pr-cvs1:/tmp/cvs-serv31743a/bacfug/modus/caching Added Files: serverscopecache.cfc Log Message: an implementation of caching that uses the server scope --- NEW FILE: serverscopecache.cfc --- <cfcomponent hint="Uses the server scope for caching" extends="org.bacfug.modus.caching.baseCache"> <!--- is the cache primed ---> <cffunction name="isCacheInitialized" access="public" output="no" returnType="boolean" hint="Returns a boolean for whether the cache is initialized"> <cfreturn structKeyExists(server,"modus") AND structKeyExists(server.modus,"contentObjectCache") AND structKeyExists(server.modus.contentObjectCache,"objectInstances")> </cffunction> <!--- initialize the cache ---> <cffunction name="cacheInit" access="public" output="no" returnType="void" hint="Initializes the in-memory cache"> <cfparam name="server.modus" default="#structNew()#"> <cfscript> server.modus.contentObjectCache = structNew(); server.modus.contentObjectCache.objectInstances = structNew(); server.modus.contentObjectCache.objectTypes = structNew(); </cfscript> </cffunction> <!--- is a particular object instance in the cache? ---> <cffunction name="isObjectCached" access="public" output="no" returnType="boolean" hint="Returns a boolean for whether a particular object (Based on ID) is cached"> <cfargument name="id" required="yes" type="string"> <cfreturn structKeyExists(server.modus.contentObjectCache.objectInstances,arguments.id)> </cffunction> <!--- put an object in the cache ---> <cffunction name="putObject" access="public" output="no" returnType="void" hint="Put a contentObject instance into the cache"> <cfargument name="contentObject" required="yes" type="org.bacfug.modus.baseContentObject"> <cfscript> server.modus.contentObjectCache.objectInstances[arguments.contentObject.getID()] = arguments.contentObject.makeClone(); </cfscript> </cffunction> <!--- get an object from the cache ---> <cffunction name="getObject" access="public" output="no" returnType="org.bacfug.modus.baseContentObject" hint="get an object instance from the cache"> <cfargument name="id" required="yes" type="string"> <cfif NOT isObjectCached(arguments.id)> <cfthrow type="modus.badCacheRequest" message="Object does not exist in the cache" detail="The contentObject with ID ""#arguments.id#"" does not exist in the cache. You may not request an object that is not cached."> </cfif> <cfreturn server.modus.contentObjectCache.objectInstances[arguments.id]> </cffunction> </cfcomponent> |