public async Task ExecuteAsync <TResult>(ChoosenNode choosenNode, JsonOperationContext context, RavenCommand <TResult> command, CancellationToken token = default(CancellationToken)) { string url; var request = CreateRequest(choosenNode.Node, command, out url); long cachedEtag; BlittableJsonReaderObject cachedValue; HttpCache.ReleaseCacheItem cachedItem; using (cachedItem = GetFromCache(context, command, request, url, out cachedEtag, out cachedValue)) { if (cachedEtag != 0) { var aggresiveCacheOptions = AggressiveCaching.Value; if (aggresiveCacheOptions != null && cachedItem.Age < aggresiveCacheOptions.Duration) { command.SetResponse(cachedValue); return; } request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"" + cachedEtag + "\"")); } var sp = Stopwatch.StartNew(); HttpResponseMessage response; try { response = await _httpClient.SendAsync(request, token).ConfigureAwait(false); sp.Stop(); } catch (HttpRequestException e) // server down, network down { sp.Stop(); await HandleServerDown(choosenNode, context, command, e); return; } finally { var requestTimeInMilliseconds = sp.ElapsedMilliseconds; choosenNode.Node.UpdateRequestTime(requestTimeInMilliseconds); if (choosenNode.SkippedNodes != null) { foreach (var skippedNode in choosenNode.SkippedNodes) { skippedNode.DecreaseRate(requestTimeInMilliseconds); } } } if (response.StatusCode == HttpStatusCode.NotModified) { cachedItem.NotModified(); command.SetResponse(cachedValue); return; } if (response.IsSuccessStatusCode == false) { if (await HandleUnsuccessfulResponse(choosenNode, context, command, response, url)) { return; } } if (response.Content.Headers.ContentLength.HasValue && response.Content.Headers.ContentLength == 0) { return; } await command.ProcessResponse(context, _cache, response, url); } }
private HttpCache.ReleaseCacheItem GetFromCache <TResult>(JsonOperationContext context, RavenCommand <TResult> command, HttpRequestMessage request, string url, out long cachedEtag, out BlittableJsonReaderObject cachedValue) { if (command.IsReadRequest) { if (request.Method != HttpMethod.Get) { url = request.Method + "-" + url; } return(_cache.Get(context, url, out cachedEtag, out cachedValue)); } cachedEtag = 0; cachedValue = null; return(new HttpCache.ReleaseCacheItem()); }
public async Task ExecuteAsync <TResult>(RavenCommand <TResult> command, JsonOperationContext context, CancellationToken token = default(CancellationToken)) { var choosenNode = ChooseNodeForRequest(command); await ExecuteAsync(choosenNode, context, command, token); }
public void Execute <TResult>(RavenCommand <TResult> command, JsonOperationContext context) { AsyncHelpers.RunSync(() => ExecuteAsync(command, context)); }
public void Execute <TResult>(RavenCommand <TResult> command, CancellationToken cancellationToken = default(CancellationToken)) { RequestExecutor.Execute(command, Context, cancellationToken); }
public Task ExecuteAsync <TResult>(RavenCommand <TResult> command, CancellationToken cancellationToken = default(CancellationToken)) { return(RequestExecutor.ExecuteAsync(command, Context, cancellationToken)); }
public void Execute <TResult>(RavenCommand <TResult> command) { RequestExecutor.Execute(command, Context); }