public static async Task <UserInfo> EnsureGetUserInfo(this OsuApiClient osuApi, string name, Bleatingsheep.Osu.Mode mode) { var(success, result) = await osuApi.GetUserInfoAsync(name, mode); ExecutingException.Ensure(success, "网络错误。"); ExecutingException.Ensure(result != null, "无此用户!"); return(result); }
public static async Task <(bool, UserInfo)> GetCachedUserInfo(this OsuApiClient osuApi, int id, Bleatingsheep.Osu.Mode mode) { var hasCache = s_cache.TryGetValue <UserInfo>((id, mode), out var cachedInfo); if (hasCache) { return(true, cachedInfo); } var(success, userInfo) = await osuApi.GetUserInfoAsync(id, mode); if (success) { s_cache.Set((id, mode), userInfo, CacheAvailable); return(true, userInfo); } else { // fail return(default);