public async Task <ApiKey?> GetAsync(string key) { if (string.IsNullOrWhiteSpace(key) || !Guid.TryParse(key, out Guid id)) { return(null); } // Check the cache var cacheResult = await cache.GetAsync(key); if (cacheResult != null) { return(cacheResult); } // Check the db var dbResult = await repository.GetAsync(id); if (dbResult == null) { return(null); } // Update the cache with the entry await cache.SetAsync(key, dbResult); return(dbResult); }
public async Task HandleAsync(ApiKeyCreated @event) { var apiKey = await _apiKeyRepository.GetAsync(@event.ApiKey); if (apiKey.HasValue) { return; } await _apiKeyRepository.AddAsync(new ApiKeyDto { Id = Guid.NewGuid(), UserId = @event.UserId, Key = @event.ApiKey }); }
public async Task <Maybe <ApiKey> > GetAsync(Guid id) => await _repository.GetAsync(id);