| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | <?php	/**	* @desc 	* 	* memcache class	*/	class Mcache {				public $is_compress = false;		public $expire = false;		public $cache;				public function Mcache($g_memcahe_conf) {			$this->is_compress = COMPRESSED ? MEMCACHE_COMPRESSED : false;			$this->expire   = MEM_EXPIRES ? MEM_EXPIRES : false;			$this->cache	= new Memcache();			$this->connect($g_memcahe_conf);		}		/**		* @desc 		*  添加Memcache地址, 打开一个到Memcache的连接		*/		public function connect($g_memcahe_conf) {						// multi-server config			if(!empty($g_memcahe_conf[0])){				foreach ($g_memcahe_conf as $conf){					$this->cache->addServer($conf['server'], $conf['port'], $conf['per'], $conf['weight'], $conf['timeout'],  $conf['retry']);				}							}			// single server config			else{				$this->cache->addServer(					$g_memcahe_conf['server'], 					$g_memcahe_conf['port'], 					$g_memcahe_conf['per'], 					$g_memcahe_conf['weight'], 					$g_memcahe_conf['timeout'], 					$g_memcahe_conf['retry']);			}		}		/**		* @desc 		*  向Memcache添加一个值,如果已经存在,则覆写		*/		public function set($key, $val) {			return $this->cache->set($key, $val, $this->is_compress,$this->expire);		}		/**		* @desc 		* 添加一个值,如果已经存在,则返回false		*/		public function add($key, $val) {			return $this->cache->add($key, $val, $this->is_compress,$this->expire);		}		/**		* @desc 		* 替换一个已经存在Memcache服务器上的项目(功能类似Memcache::set)		*/		public function replace($key, $val) {			return $this->cache->replace($key, $val, $this->is_compress,$this->expire);					}		/**		* @desc 		* 删除一个Memcache上的key值		*/		public function del($key) {			return $this->cache->delete($key);		}		/**		* @desc 		* 刷新所有Memcache上保存的项目		*/		public function flush() {			return $this->cache->flush();		}		/**		* @desc 		* 从Memcache上获取一个key值		* 		*/		public function get($key) {			return $this->cache->get($key);		}		/**		* @desc 		* 获取进程池中所有进程的运行系统统计		*/		public function getStats($par="") {			return $this->cache->getExtendedStats($par);		}	}?>
 |