private void StartPurging() { var emptyRequest = new Request <QuotaKeeperRequest, string>(QuotaKeeperRequest.Reserve(0)); _reserveQueue.Add(emptyRequest); _taskTracker.Add(() => emptyRequest.WaitForCompleteAsync()); }
/// <inheritdoc /> public override void Calibrate() { if (_rules.Any(r => r.CanBeCalibrated)) { _reserveQueue.Add(new Request <QuotaKeeperRequest, string>(QuotaKeeperRequest.Calibrate())); } }
/// <inheritdoc /> public override async Task <ReserveTransaction> ReserveAsync(long contentSize) { var reserveRequest = new Request <QuotaKeeperRequest, string>(QuotaKeeperRequest.Reserve(contentSize)); _reserveQueue.Add(reserveRequest); string result = await reserveRequest.WaitForCompleteAsync(); if (result != null) { throw new CacheException($"Failed to reserve space for content size=[{contentSize}], result=[{result}]"); } return(new ReserveTransaction(contentSize, Evicted)); }
/// <inheritdoc /> public override async Task SyncAsync(Context context, bool purge) { // Ensure there are no pending requests. var request = new Request <QuotaKeeperRequest, string>(purge ? QuotaKeeperRequest.Reserve(0) :QuotaKeeperRequest.Synchronize()); _reserveQueue.Add(request); await request.WaitForCompleteAsync(); var purgeTask = _purgeTask; if (purgeTask != null) { // Can ignore the result because purgeTask should never fail. (await purgeTask).ThrowIfFailure(); } }