Example #1
0
 /**
  * 返回用户信息,增加缓存
  *
  * @param string $_user_id        	
  * @param bool $big_photo
  *        	false
  * @param number $cache_time
  *        	3600
  * @return array 不管用户是否存在都返回相关信息,可以使用字段“Account”判断用户是否存在
  */
 protected function getUserInfo($_user_id, $big_photo = false, $cache_time = 3600)
 {
     if (empty($_user_id)) {
         return array();
     }
     $_key = md5(__METHOD__ . $_user_id . $big_photo);
     $cache_info = $this->cacheData($_key, null, $cache_time);
     debugLog(__METHOD__ . ':cache:' . !empty($this->cache_obj) . ':' . $_key . ':' . $_user_id, empty($cache_info['user_id']) ? 'miss' : 'hit');
     if (!empty($cache_info['user_id'])) {
         return $cache_info;
     } else {
         $_data = User::GetProfile($_user_id);
         debugLog(__METHOD__ . ':User::GetProfile:' . $_user_id, $_data);
         $return['user_id'] = $_user_id;
         $return['nickname'] = empty($_data['nickname']) ? $_user_id : $_data['nickname'];
         $return['head'] = empty($_data['head']) ? null : $_data['head'];
         $return['photo'] = User::GetPhotoUrl($_user_id, $big_photo, $return['head']);
         $return['user_url'] = User::UserUrl($_user_id);
         // 可以使用这个字段来判断用户是否存在
         $return['Account'] = empty($_data['Account']) ? null : $_data['Account'];
         $this->cacheData($_key, $return, $cache_time);
         return $return;
     }
 }