public async Task <IEnumerable <SecurityKey> > Generate(JwtEnpoint endpoint, string type, string configuration) { var configurationObj = JsonSerializerHelper.Deserialize <RsaConfiguration>(configuration); IEnumerable <SecurityKey> keys = new List <SecurityKey>(); CacheTimeContainer <IEnumerable <SecurityKey> > cacheItem; bool needCreate = true; if (configurationObj.Cache) { if (endpoint.Extensions.TryGetValue(_cacheAttributeName, out Object objValidateSignKeyCache)) { cacheItem = (CacheTimeContainer <IEnumerable <SecurityKey> >)objValidateSignKeyCache; if (!cacheItem.Expire()) { needCreate = false; keys = cacheItem.Value; } } if (needCreate) { keys = await getSecurityKeys(configurationObj.Uri); cacheItem = new CacheTimeContainer <IEnumerable <SecurityKey> >(keys, configurationObj.Timeout); endpoint.SetExtension(_cacheAttributeName, cacheItem); } } else { keys = await getSecurityKeys(configurationObj.Uri); } return(keys); }
public HashGroup QueryByNameSync(string name) { CacheTimeContainer <HashGroup> groupItem = _groupsByName.GetValue(name); if (groupItem == null || groupItem.Expire()) { var group = _hashGroupRepository.QueryByNameSync(name); groupItem = new CacheTimeContainer <HashGroup>(group, CacheTimeout); _groupsByName.SetValue(name, groupItem); } return(groupItem.Value); }
public async Task <HttpClaimGenerator> QueryByName(string name) { CacheTimeContainer <HttpClaimGenerator> generatorItem = _generatorsByName.GetValue(name); if (generatorItem == null || generatorItem.Expire()) { var generator = await _httpClaimGeneratorRepository.QueryByName(name); generatorItem = new CacheTimeContainer <HttpClaimGenerator>(generator, CacheTimeout); _generatorsByName.SetValue(name, generatorItem); } return(generatorItem.Value); }
/// <summary> /// 根据id查询 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <HashGroup> QueryById(Guid id) { CacheTimeContainer <HashGroup> groupItem = _groupsByID.GetValue(id); if (groupItem == null || groupItem.Expire()) { var group = await _hashGroupRepository.QueryById(id); groupItem = new CacheTimeContainer <HashGroup>(group, CacheTimeout); _groupsByID.SetValue(id, groupItem); } return(groupItem.Value); }
public async Task <JwtEnpoint> QueryByName(string name) { CacheTimeContainer <JwtEnpoint> endpointItem = _nameEnpoints.GetValue(name); if (endpointItem == null || endpointItem.Expire()) { var endpoint = await _jwtEnpointRepository.QueryByName(name); endpointItem = new CacheTimeContainer <JwtEnpoint>(endpoint, CacheTimeout); _nameEnpoints.SetValue(name, endpointItem); } return(endpointItem.Value); }
public async Task <AdfsEndpoint> QueryByName(string name) { CacheTimeContainer <AdfsEndpoint> serviceFactoryItem = _nameEndpoints.GetValue(name); if (serviceFactoryItem == null || serviceFactoryItem.Expire()) { var serviceFactory = await _adfsEndpointRepository.QueryByName(name); serviceFactoryItem = new CacheTimeContainer <AdfsEndpoint>(serviceFactory, CacheTimeout); _nameEndpoints.SetValue(name, serviceFactoryItem); } return(serviceFactoryItem.Value); }
public async Task <RemoteServiceDescription> QueryByName(string name) { CacheTimeContainer <RemoteServiceDescription> generatorItem = _generatorsByName.GetValue(name); if (generatorItem == null || generatorItem.Expire()) { var generator = await _remoteServiceDescriptionRepository.QueryByName(name); generatorItem = new CacheTimeContainer <RemoteServiceDescription>(generator, CacheTimeout); _generatorsByName.SetValue(name, generatorItem); } return(generatorItem.Value); }
public async Task <UserInfo> GetLoginInfo(string username, string token) { CacheTimeContainer <UserInfo> userInfoItem = _loginInfo.GetValue(token); if (userInfoItem == null || userInfoItem.Expire() || userInfoItem.Value.systemuserid.GetValueOrDefault() == Guid.Empty) { var loginModel = await _authService.GetLoginInfo(username); userInfoItem = new CacheTimeContainer <UserInfo>(loginModel, CacheTimeout); _loginInfo.SetValue(token, userInfoItem); } return(userInfoItem.Value); }
public async Task <int> QueryGroupCount(string groupName, bool isDead) { var key = $"{groupName}-{Convert.ToInt32(isDead).ToString()}"; CacheTimeContainer <int> countItem = _queueCountByGroup.GetValue(key);; if (countItem == null || countItem.Expire()) { var queryResult = await _sQueueRepository.QueryByGroup(groupName, isDead, 1, 1); countItem = new CacheTimeContainer <int>(queryResult.TotalCount, CacheTimeout); _queueCountByGroup.SetValue(key, countItem); } return(countItem.Value); }
public async Task <SQueue> QueryByCode(string groupName, bool isDead, int code) { var key = $"{groupName}-{Convert.ToInt32(isDead).ToString()}-{code.ToString()}"; CacheTimeContainer <SQueue> queueItem = _queuesByCode.GetValue(key); if (queueItem == null || queueItem.Expire()) { var squeue = await _sQueueRepository.QueryByCode(groupName, isDead, code); queueItem = new CacheTimeContainer <SQueue>(squeue, CacheTimeout); _queuesByCode.SetValue(key, queueItem); } return(queueItem.Value); }
public async Task <V> Get <K, V>(string cacheConfiguration, Func <Task <V> > creator, string prefix, K key) { var configuration = JsonSerializerHelper.Deserialize <KVCacheConfiguration>(cacheConfiguration); if (!_datas.TryGetValue(prefix, out CacheContainer cacheContainer)) { await _lock.WaitAsync(); try { if (!_datas.TryGetValue(prefix, out cacheContainer)) { cacheContainer = new CacheContainer() { CacheDict = new HashLinkedCache <object, CacheTimeContainer <object> >() { Length = configuration.MaxLength } }; _datas[prefix] = cacheContainer; } } finally { _lock.Release(); } } CacheTimeContainer <object> cacheItem = cacheContainer.CacheDict.GetValue(key); if (cacheItem == null || cacheItem.Expire()) { await cacheContainer.SyncOperate( async() => { cacheItem = cacheContainer.CacheDict.GetValue(key); if (cacheItem == null || cacheItem.Expire()) { var cacheValue = await creator(); cacheItem = new CacheTimeContainer <object>(cacheValue, configuration.ExpireSeconds); cacheContainer.CacheDict.SetValue(key, cacheItem); } } ); } return((V)cacheItem.Value); }