예제 #1
0
        private async Task LoadFromPeerAsync(string key, Stream sink, ICacheControl cacheControl, IGroupCacheClient peerClient, CancellationToken ct)
        {
            try
            {
                Stats.TracePeerLoads(_groupName);
                using (var validatingSink = CacheEntryValidator.ValidateEntryPassThrough(key, sink))
                {
                    await peerClient.GetAsync(_groupName, key, validatingSink, cacheControl, ct).ConfigureAwait(false);

                    await validatingSink.ValidateAsync(ct).ConfigureAwait(false);
                }
            }
            catch (CircuitBreakerOpenException)
            {
                throw; // Dont log CircuitBreakerOpenException
            }
            catch (InternalServerErrorException internalErrorEx)
            {
                Logger.Error(String.Format("Call to LoadFromPeer to {0} for Cache {1} key: {2} failed on InternalServerErrorException {3}", peerClient.Endpoint.ToString(), _groupName, key, internalErrorEx.Message));
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, String.Format("Call to LoadFromPeer to {0} for Cache {1} key: {2} failed ", peerClient.Endpoint.ToString(), _groupName, key));
                throw;
            }
        }
 public async Task GetAsync(string group, string key, Stream sink, ICacheControl cacheControl, CancellationToken ct)
 {
     try
     {
         TripIfNeeded();
         await _client.GetAsync(group, key, sink, cacheControl, ct).ConfigureAwait(false);
     }
     catch (ServerBusyException)
     {
         // Dont count busy server as bad
         throw;
     }
     catch
     {
         CountFailure();
         throw;
     }
     ResetCount();
 }
예제 #3
0
        public void Configuration(IAppBuilder app)
        {
            app.Run(async context =>
            {
                var request       = context.Request;
                var response      = context.Response;
                var CallCancelled = context.Request.CallCancelled;


                var form      = await request.ReadFormAsync();
                var groupName = form.Get(GROUPNAME);
                var key       = form.Get(KEY);

                if (groupName == null || key == null)
                {
                    response.StatusCode = 400; //BadRequest;
                    return;
                }

                response.ContentType = "application/octet-stream";
                try
                {
                    var cacheControl = new OwinCacheControl(context.Response.Headers);
                    await _handler.GetAsync(groupName, key, response.Body, cacheControl, CallCancelled);
                }
                catch (GroupNotFoundException ex)
                {
                    response.StatusCode   = 404;
                    response.ReasonPhrase = ex.ToString();
                }
                catch (ServerBusyException busy)
                {
                    response.StatusCode   = 503;
                    response.ReasonPhrase = busy.ToString();
                }
                catch (Exception ex)
                {
                    response.StatusCode   = 500;
                    response.ReasonPhrase = ex.ToString();
                }
            });
        }