public async Task <string[]> GetEnumerationValuesAsync(string enumName, CancellationToken cancellationToken) { var resource = $"enumerations/{enumName}"; var cached = (string[])(await _cacheProvider.GetCacheItemAsync(resource, cancellationToken)); if (cached != null) { return(cached); } _logger.Info($"Calling {resource} on translator api"); var request = new RestRequest(resource, Method.GET); request.AppendContext(_executionContextManager.SpiExecutionContext); var response = await _restClient.ExecuteTaskAsync(request, cancellationToken); if (!response.IsSuccessful) { throw new TranslatorApiException(resource, response.StatusCode, response.Content); } _logger.Debug($"Received {response.Content}"); var result = JsonConvert.DeserializeObject <GetEnumerationValuesResult>(response.Content); await _cacheProvider.AddCacheItemAsync(resource, result.EnumerationValuesResult.EnumerationValues, new TimeSpan(0, 1, 0), cancellationToken); return(result.EnumerationValuesResult.EnumerationValues); }
private async Task <Dictionary <string, Dictionary <string, string[]> > > GetMappings(CancellationToken cancellationToken) { const string cacheKey = "AllEnumMappings"; var cached = (Dictionary <string, Dictionary <string, string[]> >)(await _cacheProvider.GetCacheItemAsync(cacheKey, cancellationToken)); if (cached != null) { return(cached); } var mappings = await GetMappingsFromApi(cancellationToken); if (mappings != null) { await _cacheProvider.AddCacheItemAsync(cacheKey, mappings, new TimeSpan(0, 1, 0), cancellationToken); } return(mappings); }