/// <summary> /// 异步获取或刷新在线用户信息 /// </summary> /// <param name="userName">用户名</param> /// <returns>在线用户信息</returns> public virtual async Task <OnlineUser> GetOrRefreshAsync(string userName) { string key = $"Identity_OnlineUser_{userName}"; DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); options.SetSlidingExpiration(TimeSpan.FromMinutes(30)); return(await _cache.GetAsync <OnlineUser>(key, () => { return _serviceProvider.ExecuteScopedWorkAsync <OnlineUser>(async provider => { IOnlineUserProvider onlineUserProvider = provider.GetService <IOnlineUserProvider>(); return await onlineUserProvider.Create(provider, userName); }); }, options)); }
/// <summary> /// 获取或刷新在线用户信息 /// </summary> /// <param name="userName">用户名</param> /// <returns>在线用户信息</returns> public virtual OnlineUser GetOrRefresh(string userName) { string key = $"Identity_OnlineUser_{userName}"; DistributedCacheEntryOptions options = new DistributedCacheEntryOptions(); options.SetSlidingExpiration(TimeSpan.FromMinutes(30)); return(_cache.Get <OnlineUser>(key, () => { return ServiceLocator.Instance.ExecuteScopedWork <OnlineUser>(provider => { IOnlineUserProvider onlineUserProvider = provider.GetService <IOnlineUserProvider>(); return onlineUserProvider.Create(provider, userName).Result; }); }, options)); }