Пример #1
0
        private async Task <bool> HasInvalidStatusCode(
            LastChangedRecord record,
            RedisStore redisStore,
            int responseStatusCode,
            string requestUrl,
            HttpResponseMessage response)
        {
            if (_validStatusCodes.Contains(responseStatusCode))
            {
                return(false);
            }

            _logger.LogWarning(
                "Backend call to {RequestUrl} ({AcceptType}) returned statuscode {StatusCode} which was invalid.",
                requestUrl,
                record.AcceptType,
                response.StatusCode);

            record.ErrorCount++;
            record.LastError        = DateTimeOffset.UtcNow;
            record.LastErrorMessage = $"Backend call to {requestUrl} ({record.AcceptType}) returned statuscode {response.StatusCode} which was invalid.";

            if (record.ErrorCount >= _maxErrorCount)
            {
                _logger.LogInformation(
                    "{CacheKey} reached {MaxErrorCount} errors, purging from cache.",
                    record.CacheKey.ToLowerInvariant(),
                    record.ErrorCount);

                await redisStore.DeleteKeyAsync(record.CacheKey.ToLowerInvariant());
            }

            return(true);
        }
Пример #2
0
        private async Task <bool> EligibleForDeletion(
            LastChangedRecord record,
            RedisStore redisStore,
            int responseStatusCode,
            string requestUrl,
            HttpResponseMessage response)
        {
            if (!_validStatusCodesToDelete.Contains(responseStatusCode))
            {
                return(false);
            }

            _logger.LogInformation(
                "Backend call to {RequestUrl} ({AcceptType}) returned statuscode {StatusCode} which is eligible for deletion. ({CacheKey})",
                requestUrl,
                record.AcceptType,
                response.StatusCode,
                record.CacheKey.ToLowerInvariant());

            await redisStore.DeleteKeyAsync(record.CacheKey.ToLowerInvariant());

            record.LastPopulatedPosition = record.Position;
            return(true);
        }