[pLog-svn] r4788 - plog/branches/lifetype-1.2/class/config

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Feb 19 16:15:42 EST 2007


Author: oscar
Date: 2007-02-19 16:15:41 -0500 (Mon, 19 Feb 2007)
New Revision: 4788

Modified:
   plog/branches/lifetype-1.2/class/config/configdbstorage.class.php
Log:
the Config class is always accessed via a singleton so we should be able to safely load its data in the constructor and keep it there during the lifetime of the current instance of the class, instead of going back to the cache to check/load the data every time in Config::getValue(). This seems to save plenty of method and function calls to (according to xdebug, about 7000) They're mostly calls to built-in PHP functions, but function calls nevertheless.

Modified: plog/branches/lifetype-1.2/class/config/configdbstorage.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/config/configdbstorage.class.php	2007-02-19 20:55:46 UTC (rev 4787)
+++ plog/branches/lifetype-1.2/class/config/configdbstorage.class.php	2007-02-19 21:15:41 UTC (rev 4788)
@@ -50,9 +50,15 @@
     	function ConfigDbStorage()
         {            
 		    $this->_cache =& CacheManager::getCache();
+		
+			// load data from the databas, but only if it was already not in the cache
+			if( (!$this->_data = $this->_cache->getData( CACHE_CONFIGDBSTORAGE, CACHE_GLOBAL ))) {
+				$this->_loadAllValuesFromDatabase();				
+			}
         }
 
-        function _loadAllValuesFromDatabase() {
+        function _loadAllValuesFromDatabase() 
+		{
             // initialize the database
             $this->_initializeDatabase();
 
@@ -67,7 +73,8 @@
          * Initialize the Database to allow db access
          *
          */
-        function _initializeDatabase() {
+        function _initializeDatabase() 
+		{
             if ($this->_db == null) {
                 // source the neccessary class files
                 lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
@@ -127,10 +134,6 @@
 		 */
         function getValue( $key, $defaultValue = null )
         {
-			if( (!$this->_data = $this->_cache->getData( CACHE_CONFIGDBSTORAGE, CACHE_GLOBAL ))) {
-				$this->_loadAllValuesFromDatabase();				
-			}
-			
             if( array_key_exists($key, $this->_data) ) {
                 if ($this->_data[$key] == "" || $this->_data[$key] == null) {
                     return $defaultValue;
@@ -356,4 +359,4 @@
             return $result;
         }
     }
-?>
+?>
\ No newline at end of file



More information about the pLog-svn mailing list