/** * 获取当前缓存对象实例 * @access public * @return XF_Cache_Memcache */ public static function getInstance() { if (self::$_instance == null) { //是否存在memcache缓存服务器配置 $servers = XF_Config::getInstance()->getMemcaches(); if (!isset($servers[0])) { throw new XF_Cache_Exception('Memcache server config is empty'); } $server = explode(':', $servers[0]); //检测是否安装memcache PHP扩展 if (!class_exists('Memcache', FALSE)) { throw new XF_Cache_Exception('Memcache PECL expands has not installed or has begun using'); } self::$_instance = new self(); self::$_instance->_memcache = new Memcache(); $status = self::$_instance->_memcache->connect($server[0], $server[1]); if ($status == FALSE) { throw new XF_Cache_Exception('Memcache connect failure'); } } return self::$_instance; }