示例#1
0
 public void Calibrate()
 {
     if (_rules.Any(r => r.CanBeCalibrated))
     {
         var request = QuotaRequest.Calibrate();
         _reserveQueue.Add(request);
     }
 }
示例#2
0
        private Task <BoolResult> SendPurgeRequest(OperationContext context, string reason)
        {
            return(context.PerformOperationAsync(
                       Tracer,
                       () =>
            {
                var emptyRequest = QuotaRequest.Purge();
                _reserveQueue.Add(emptyRequest);

                return emptyRequest.CompletionAsync();
            },
                       traceErrorsOnly: true));
        }
示例#3
0
        private Task <BoolResult> SendPurgeRequest(OperationContext context, string reason)
        {
            return(context.PerformOperationAsync(
                       _tracer,
                       () =>
            {
                var emptyRequest = QuotaRequest.Purge();
                _reserveQueue.Add(emptyRequest);

                return emptyRequest.CompletionAsync();
            },
                       extraStartMessage: $"Requesting purge due to '{reason}'."));
        }
示例#4
0
        private Task <BoolResult> SendSyncRequest(OperationContext context, bool purge)
        {
            if (purge)
            {
                return(SendPurgeRequest(context, "Sync"));
            }

            return(context.PerformOperationAsync(
                       Tracer,
                       () =>
            {
                var emptyRequest = QuotaRequest.Synchronize();
                _reserveQueue.Add(emptyRequest);

                return emptyRequest.CompletionAsync();
            }));
        }
示例#5
0
        public async Task <ReserveTransaction> ReserveAsync(long contentSize)
        {
            Contract.Assert(contentSize >= 0);

            ShutdownStartedCancellationToken.ThrowIfCancellationRequested();

            var reserveRequest = QuotaRequest.Reserve(contentSize);

            // To avoid potential race condition need to increase size first and only after that to add the request into the queue.
            IncreaseSize(ref _requestedSize, reserveRequest.ReserveSize);
            _reserveQueue.Add(reserveRequest);

            BoolResult result = await reserveRequest.CompletionAsync();

            if (!result)
            {
                throw new CacheException($"Failed to reserve space for content size=[{contentSize}], result=[{result}]");
            }

            return(new ReserveTransaction(reserveRequest, OnReservationCommitted));
        }