public async Task <UserApiKey[]> GetApiKeysByIdsAsync(string[] ids) { var cacheKey = CacheKey.With(GetType(), nameof(GetApiKeysByIdsAsync), string.Join("-", ids)); return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { //Add cache expiration token cacheEntry.AddExpirationToken(ApiKeyCacheRegion.CreateChangeToken()); using (var repository = _repositoryFactory()) { var result = await repository.UserApiKeys.Where(x => ids.Contains(x.Id)) .AsNoTracking() .ToArrayAsync(); return result.Select(x => x.ToModel(AbstractTypeFactory <UserApiKey> .TryCreateInstance())).ToArray(); } })); }
public async Task <UserApiKey> GetApiKeyByKeyAsync(string apiKey) { var cacheKey = CacheKey.With(GetType(), nameof(GetApiKeyByKeyAsync), apiKey); return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { //Add cache expiration token cacheEntry.AddExpirationToken(ApiKeyCacheRegion.CreateChangeToken()); using (var repository = _repositoryFactory()) { var result = await repository.UserApiKeys.Where(x => x.ApiKey == apiKey) .AsNoTracking() .FirstOrDefaultAsync(); return result?.ToModel(AbstractTypeFactory <UserApiKey> .TryCreateInstance()); } })); }