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(); }
/** * 设置缓存 * @param string $file 缓存名 模块:缓存名 * @param mixed $value 缓存值 WEB_DEPLOY_TYPE配置集群部署可为空 * @param mixed $expire 缓存有效时间 * @param array $data 包含 status 返回数据 0:无需 1:需要 dir:缓存路径 expire: 缓存有效时间 at:缓存方式 * @return mixed */ function setCache($string, $value = NULL, $expire = 0, $data = array()) { $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'] = $module; $para['a'] = 'Set'.ucwords($name); $para['name'] = $name; $data['name'] = $name; $data['dir'] = $data['dir'] ? $module.'/'.$data['dir'] : $module; $data['module'] = $module; //dump($data);//exit; $result = json_decode($cache->set($para,$data),true); }else{ $dir = $module; $options['temp'] = C('DATA_CACHE_PATH').$dir; $options['filename'] = $name; $result = S($name,$value,$options); } if($result['error']==0){ return true; }else{ return false; } }