/** * Returns an instance of the global cache. * The cache type used is defined in options. * * @return vB_Cache - Reference to instance of the cache handler */ public static function instance($type = self::CACHE_STD) { $DEFAULTS_CACHETYPE = self::getDefaults(); $vb5_config =& vB::getConfig(); if (!empty($vb5_config['Misc']['debug']) and !empty($_REQUEST['nocache'])) { self::$disableCache = 1; } if (!isset(self::$instance[$type])) { if (!isset($vb5_config['Cache']) or !isset($vb5_config['Cache']['class']) or !is_array($vb5_config['Cache']['class']) or !isset($vb5_config['Cache']['class'][$type])) { $cacheClass = $DEFAULTS_CACHETYPE[$type]; } else { $cacheClass = $vb5_config['Cache']['class'][$type]; } // if more than 1 of the 3 types (STD, FAST, LARGE) are using the same implementation, // don't create a new instance, just share the same one. foreach (array(self::CACHE_STD, self::CACHE_FAST, self::CACHE_LARGE) as $cacheType) { if (!empty(self::$instance[$cacheType]) and is_a(self::$instance[$cacheType], $cacheClass)) { self::$instance[$type] = self::$instance[$cacheType]; return self::$instance[$type]; } } // call constructor directly. Having static functions with the same name but different // semantics in the subclasses works, but its tacky. self::$instance[$type] = new $cacheClass($type); //call_user_func(array($cacheClass, 'instance')); vB_Shutdown::instance()->add(array(self::$instance[$type], 'shutdown')); } return self::$instance[$type]; }