public CacheMessageHandler(HttpMessageHandler httpMessageHandler, IApiCacheService apiCache, IConnectivityService connectivity) { _httpMessageInvoker = new HttpMessageInvoker(httpMessageHandler); ApiCacheService = apiCache; ConnectivityService = connectivity; }
public CmsApiService( CmsApiClientOptions cmsApiClientOptions, IApiDataProcessorService apiDataProcessorService, HttpClient httpClient, IMapper mapper, IApiCacheService apiCacheService, IContentTypeMappingService contentTypeMappingService) { this.cmsApiClientOptions = cmsApiClientOptions; this.apiDataProcessorService = apiDataProcessorService; this.httpClient = httpClient; this.mapper = mapper; this.apiCacheService = apiCacheService; this.contentTypeMappingService = contentTypeMappingService; }
public CacheReloadService( ILogger <CacheReloadService> logger, AutoMapper.IMapper mapper, IEventMessageService <ContentPageModel> eventMessageService, ICmsApiService cmsApiService, IContentCacheService contentCacheService, IAppRegistryApiService appRegistryService, IContentTypeMappingService contentTypeMappingService, IApiCacheService apiCacheService) { this.logger = logger; this.mapper = mapper; this.eventMessageService = eventMessageService; this.cmsApiService = cmsApiService; this.contentCacheService = contentCacheService; this.appRegistryService = appRegistryService; this.contentTypeMappingService = contentTypeMappingService; this.apiCacheService = apiCacheService; }
private async Task <HttpResponseMessage> GetFromCacheOrSendRequest(HttpRequestMessage request, int expireInSeconds, IApiCacheService cacheService, CancellationToken cancellationToken) { if (cacheService.TryGet(request, out var responseMessage)) { return(responseMessage); } Exception exception = null; var canDoRequest = await ConnectivityService.CanDoRequest(request); if (canDoRequest) { try { responseMessage = await _httpMessageInvoker.SendAsync(request, cancellationToken); } catch (Exception ex) { responseMessage.StatusCode = System.Net.HttpStatusCode.BadRequest; exception = ex; } } else { responseMessage.StatusCode = System.Net.HttpStatusCode.BadGateway; exception = new ConnectivityException(request); } if (responseMessage.IsSuccessStatusCode) { await cacheService.Add(request, responseMessage, TimeSpan.FromSeconds(expireInSeconds)); } else if (exception != null) { throw exception; } return(responseMessage); }