From: <ndi...@us...> - 2002-10-05 00:52:31
|
Update of /cvsroot/modus/org/bacfug/modus/persistence In directory usw-pr-cvs1:/tmp/cvs-serv31929/bacfug/modus/persistence Modified Files: basepersister.cfc Log Message: removed caching and refactored it into its own object, so we now have an instance.cache -- eventually, this should not need to be instantiated every time the persister is. Index: basepersister.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/persistence/basepersister.cfc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** basepersister.cfc 12 Sep 2002 19:19:55 -0000 1.8 --- basepersister.cfc 5 Oct 2002 00:52:28 -0000 1.9 *************** *** 3,13 **** <cffunction name="init" access="public" hint="The initializer" returnType="org.bacfug.modus.persistence.basePersister" output="no"> <cfscript> ! //make sure the cache is initialized ! if(NOT isCacheInitialized()) ! cacheInit(); </cfscript> <cfreturn this> </cffunction> <cffunction name="save" access="public" output="no" hint="The method to save data"> <cfthrow message="save() method not implemented!" detail="You must defined a save() method for #getMetaData(this).name#."> --- 3,16 ---- <cffunction name="init" access="public" hint="The initializer" returnType="org.bacfug.modus.persistence.basePersister" output="no"> <cfscript> ! //the cache we should use ! instance.cache = createObject("component",getCachePath()); </cfscript> <cfreturn this> </cffunction> + <cffunction name="getCachePath" access="private" returntype="string" output="no" hint="returns a string with the path to the cache component to use. you can override this function in a persister implementation if you want to use a different caching mechanism other than the default."> + <cfreturn "org.bacfug.modus.caching.serverScopeCache"> + </cffunction> + <cffunction name="save" access="public" output="no" hint="The method to save data"> <cfthrow message="save() method not implemented!" detail="You must defined a save() method for #getMetaData(this).name#."> *************** *** 155,202 **** <cfreturn contentObjectFromSerializable(deserializedObject)> </cfif> ! </cffunction> ! ! <!--- is the cache primed ---> ! <cffunction name="isCacheInitialized" access="package" 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="package" 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="package" 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"> ! <cfscript> ! if(NOT isCacheInitialized()){ ! cacheInit(); ! } ! </cfscript> ! <cfreturn structKeyExists(server.modus.contentObjectCache.objectInstances,arguments.id)> ! </cffunction> ! ! <!--- put an object in the cache ---> ! <cffunction name="cachePutObject" access="package" 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="cacheGetObject" access="package" 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> --- 158,162 ---- <cfreturn contentObjectFromSerializable(deserializedObject)> </cfif> ! </cffunction> </cfcomponent> |