Exemplo n.º 1
0
 public static function getCoordinates($checkCache = true)
 {
     $response = new ApiResponseModel();
     $data = array();
     if ($checkCache) {
         $data = ApiCache::get(Yii::app()->params['cache']['keys']['coordinates']);
     }
     if (!$data) {
         $availableBanks = BankCourses::model()->findAvailableBanks()->findAll();
         if (count($availableBanks) > 0) {
             $ids = array();
             foreach ($availableBanks as $bankInfo) {
                 $ids[] = $bankInfo['bank_id'];
             }
             $answer = new CoordinatesApiModel();
             $coordinates = BankBranches::model()->getDepartmentCoordinates($ids)->findAll();
             foreach ($coordinates as $coordinate) {
                 $answer->add($coordinate);
             }
             $data = $answer->getResult();
             $response->setData($data);
             $response->setHash(ApiCache::set(Yii::app()->params['cache']['keys']['coordinates'], $data, Yii::app()->params['cache']['time']));
         }
     } else {
         $response->setData($data);
         $response->setHash(ApiCache::getCheck(Yii::app()->params['cache']['keys']['coordinates']));
     }
     return $response->getApiResponse();
 }
Exemplo n.º 2
0
/**
 * 获取缓存
 * @param  string $name 名称 模块:缓存名
 * @param  string $data 参数 主要包含 dir路径,获取缓存方式at
 * @return mixed
 */
function getCache($string,$data) {
	  $ar = explode(':',$string);
	  if(count($ar)>1){
		$module = $ar[0];
		$name = $ar[1];
	  }else{
		$module = CONTROLLER_NAME;
		$name = $ar[0];  
	  }
	  //集群部署
	  if(C('WEB_DEPLOY_TYPE')==1 && C('DATA_CACHE_TYPE')=='File'){
		GLOBAL $config;
		if(!$config){
			//载入配置
			require_once(C('INTERFACE_PATH')."Cache/config.php");
			require_once(C('INTERFACE_PATH')."Cache/ApiCache.class.php");
		}
		$cache = new ApiCache($config);
		$para['c'] = 'Local';
		$para['a'] = $data['at'] ? $data['at'] : 'Get';
		$para['name'] = $name;
		$data['name'] = $name;
		$dir = $data['dir'] ? $data['dir'] : '';
		$data['dir'] = $dir ? $module.'/'.$dir : $module;
		$data['module'] = $module;
		$result = json_decode($cache->get($para,$data),true);
		if($result['error_code']==0){
		  return $result['data'];
		}else{
		  return false;
		}
	  }else{
		  $dir = $module;
		  $options['temp'] = C('DATA_CACHE_PATH').$dir;
		  $options['filename'] = $name;
		  $data = S($name,'',$options);
		  return $data;
	  }
}
Exemplo n.º 3
0
 function loaddata($keystring)
 {
     $configvalue = $this->CharName_ . '_CharacterSheet';
     $CachedTime = ApiCache::get($configvalue);
     $UseCaching = config::get('API_UseCache');
     $url = API_SERVER . "/char/CharacterSheet.xml.aspx" . $keystring;
     $path = '/char/CharacterSheet.xml.aspx';
     // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round.
     if ($CachedTime == "") {
         $CachedTime = "2005-01-01 00:00:00";
         // fake date to ensure that it runs first time.
     }
     if (is_file(KB_CACHEDIR . '/api/' . $configvalue . '.xml')) {
         $cacheexists = true;
     } else {
         $cacheexists = false;
     }
     // if API_UseCache = 1 (off) then don't use cache
     if (strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0 || $UseCaching == 1 || !$cacheexists) {
         $http = new http_request($url);
         $http->set_useragent("PHPApi");
         foreach ($keystring as $key => $val) {
             $http->set_postform($key, $val);
         }
         $contents = $http->get_content();
         $start = strpos($contents, "?>");
         if ($start !== FALSE) {
             $contents = substr($contents, $start + strlen("\r\n\r\n"));
         }
         // Save the file if we're caching (0 = true in Thunks world)
         if ($UseCaching == 0) {
             $file = fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'w+');
             fwrite($file, $contents);
             fclose($file);
             @chmod(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 0666);
         }
     } else {
         // re-use cached XML
         if ($fp = @fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'r')) {
             $contents = fread($fp, filesize(KB_CACHEDIR . '/api/' . $configvalue . '.xml'));
             fclose($fp);
         } else {
             return "<i>error loading cached file " . $configvalue . ".xml</i><br><br>";
         }
     }
     return $contents;
 }