Example #1
0
	/**
	 * 获取缓存类
	 * @param string $type
	 * @return FileCache | RedisCache
	 */
	public static function getCacher ($type = '', $model = '') {
		$type or $type = C('DEFAULT_CACHER');
		if (!in_array($type, array('redis', 'file', 'remote'))) {
			$type = 'redis';
		}
		//如果不是正式服务上,不是用redis缓存
		if (false == SuiShiPHPConfig::get('PUBLIC_SERVICE') && 'redis' == $type) {
			$type = 'file';
		}
		$cacheId = $type.$model;
		if (isset(self::$CACHER[$cacheId])) {
			return self::$CACHER[$cacheId];
		}

		switch ($type) {
			case 'file':
				if (!class_exists("FileCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/FileCache.class.php';
				}
				$c = new FileCache(C('RUN_SHELL'));
				$c->setModel($model);
				$c->setPath(SuiShiPHPConfig::getFileCacheDir());
				self::$CACHER[$cacheId] = $c;
				break;
			case 'remote':
				if (!class_exists("FileCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/RemoteCacher.class.php';
				}
				$c = new RemoteCacher(C('REMOTE_CACHE_HOST'), C('REMOTE_CACHE_PORT'), 'weixinapp');
				self::$CACHER[$cacheId] = $c;
				break;
			default:
				if (!class_exists("RedisCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/RedisCache.class.php';
				}
				$c = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST'), SuiShiPHPConfig::get('REDIS_PORT'));
				self::$CACHER[$cacheId] = $c;
				break;
		}
		return self::$CACHER[$cacheId];
	}
Example #2
0
 /**
  * 获取缓存类
  * @param string $type
  * @return FileCache | RedisCache
  */
 public static function getCacher($type = '', $model = '')
 {
     $type or $type = Conf::get('DEFAULT_CACHE');
     if (!in_array($type, array('redis', 'file'))) {
         //'remote'
         $type = 'redis';
     }
     //如果不是正式服务上,不是用redis缓存
     if (true == Conf::get('DEBUG') && 'redis' == $type) {
         $type = 'file';
     }
     $cacheId = $type . $model;
     if (isset(self::$CACHER[$cacheId])) {
         return self::$CACHER[$cacheId];
     }
     switch ($type) {
         case 'file':
             $c = new FileCache();
             $c->setModel($model);
             $c->setPath(Conf::get('LOG_PATH') . 'cache');
             self::$CACHER[$cacheId] = $c;
             break;
         case 'remote':
             if (!class_exists("FileCache")) {
                 include_once SUISHI_PHP_PATH . '/Cache/RemoteCacher.class.php';
             }
             $c = new RemoteCacher(C('REMOTE_CACHE_HOST'), C('REMOTE_CACHE_PORT'), 'weixinapp');
             self::$CACHER[$cacheId] = $c;
             break;
         default:
             $c = new RedisCache(Conf::get('CACHE_REDIS_HOST'), Conf::get('CACHE_REDIS_PORT'));
             self::$CACHER[$cacheId] = $c;
             break;
     }
     return self::$CACHER[$cacheId];
 }