Module: nagvis Branch: nagvis-1.5 Commit: 5563a3578aa7bf2201d20637900302e19e01fe48 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=5563a3578aa7bf2201d20637900302e19e01fe48
Author: Lars Michelsen <[email protected]> Date: Fri Nov 26 17:41:33 2010 +0100 Fixed file cache handling when using multiple main configuration files --- share/server/core/classes/GlobalMainCfg.php | 63 +++++++++++++++++--------- 1 files changed, 41 insertions(+), 22 deletions(-) diff --git a/share/server/core/classes/GlobalMainCfg.php b/share/server/core/classes/GlobalMainCfg.php index af1221a..4d1381f 100644 --- a/share/server/core/classes/GlobalMainCfg.php +++ b/share/server/core/classes/GlobalMainCfg.php @@ -27,7 +27,7 @@ */ class GlobalMainCfg { private $useCache = true; - private $CACHES; + private $CACHE; protected $config = Array(); protected $runtimeConfig = Array(); @@ -901,35 +901,54 @@ class GlobalMainCfg { $this->configFiles = $configFiles; } - private function loadConfigFile($file) { - // Only proceed when the configuration file exists and is readable - if(!GlobalCore::getInstance()->checkExisting($file, true) || !GlobalCore::getInstance()->checkReadable($file, true)) - return false; + /** + * Get the newest of the given configuration files. This is needed to test if + * the cache file is up-to-date or needs to be renewed + * + * @author Lars Michelsen <[email protected]> + */ + private function getNewestFile() { + $age = -1; + $newestFile = ''; + foreach($this->configFiles AS $configFile) { + if(!GlobalCore::getInstance()->checkExisting($configFile, false) || !GlobalCore::getInstance()->checkReadable($configFile, false)) + continue; + + $configAge = filemtime($configFile); + if($age === -1) { + $age = $configAge; + $newestFile = $configFile; + } elseif($configAge > $age) { + $age = $configAge; + $newestFile = $configFile; + } + } - // Create instance of GlobalFileCache object for caching the config - $id = count($this->CACHES); - $this->CACHES[$id] = new GlobalFileCache(GlobalCore::getInstance(), $file, CONST_MAINCFG_CACHE.'-'.CONST_VERSION.'-cache'); - - // When this or a file before is newer than the cache parse the file - if($this->useCache > 0) - $this->useCache = $this->CACHES[$id]->isCached(false); - if($this->useCache === -1) - return $this->readConfig($file, true); + return $newestFile; } public function init() { // Get the valid configuration definitions from the available backends $this->getBackendValidConf(); - // Load all given config files - foreach($this->configFiles AS $configFile) - $this->loadConfigFile($configFile); + // Get the path and age of the newest config file + $newestFile = $this->getNewestFile(); - // Use or write the cache depending on the situation - if($this->useCache !== -1) - $this->config = $this->CACHES[0]->getCache(); - else - $this->CACHES[0]->writeCache($this->config, true); + // Use the newest file as indicator for using the cache or not + $this->CACHE = new GlobalFileCache(GlobalCore::getInstance(), $newestFile, CONST_MAINCFG_CACHE.'-'.CONST_VERSION.'-cache'); + if($this->CACHE->isCached(false) === -1) { + // The cache is too old. Load all config files + foreach($this->configFiles AS $configFile) { + // Only proceed when the configuration file exists and is readable + if(!GlobalCore::getInstance()->checkExisting($configFile, true) || !GlobalCore::getInstance()->checkReadable($configFile, true)) + return false; + $this->readConfig($configFile, true); + } + $this->CACHE->writeCache($this->config, true); + } else { + // Use the cache! + $this->config = $this->CACHE->getCache(); + } // Parse the state weight array $this->parseStateWeight(); ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
