Esempio n. 1
0
        private async Task L2OperationWithRetryOnFailureAsync(
            string operation,
            Func <string, Task> cacheOperation,
            string cacheKey,
            byte[]?bytes = null,
            bool inRetry = false)
        {
            try
            {
                var measure = await cacheOperation(cacheKey).Measure().ConfigureAwait(false);

                _logger.LogDebug($"[MsIdWeb] DistributedCache: {operation} cacheKey {cacheKey} cache size {bytes?.Length} InRetry? {inRetry} Time in Ticks: {measure.Ticks}. ");
            }
            catch (Exception ex)
            {
                _logger.LogError($"[MsIdWeb] DistributedCache: Connection issue. InRetry? {inRetry} Error message: {ex.Message} ");

                if (_distributedCacheOptions.OnL2CacheFailure != null && _distributedCacheOptions.OnL2CacheFailure(ex) && !inRetry)
                {
                    _logger.LogDebug($"[MsIdWeb] DistributedCache: Retrying {operation} cacheKey {cacheKey}. ");
                    await L2OperationWithRetryOnFailureAsync(
                        operation,
                        cacheOperation,
                        cacheKey,
                        bytes,
                        true).ConfigureAwait(false);
                }
            }
        }
Esempio n. 2
0
        private async Task L2OperationWithRetryOnFailureAsync(
            string operation,
            Func <string, Task> cacheOperation,
            string cacheKey,
            byte[]?bytes = null,
            bool inRetry = false)
        {
            try
            {
                var measure = await cacheOperation(cacheKey).Measure().ConfigureAwait(false);

                Logger.DistributedCacheStateWithTime(
                    _logger,
                    _distributedCacheType,
                    operation,
                    cacheKey,
                    bytes?.Length ?? 0,
                    inRetry,
                    measure.MilliSeconds,
                    null);
            }
            catch (Exception ex)
            {
                Logger.DistributedCacheConnectionError(
                    _logger,
                    _distributedCacheType,
                    operation,
                    inRetry,
                    ex.Message,
                    ex);

                if (_distributedCacheOptions.OnL2CacheFailure != null && _distributedCacheOptions.OnL2CacheFailure(ex) && !inRetry)
                {
                    Logger.DistributedCacheRetry(_logger, _distributedCacheType, operation, cacheKey, null);
                    await L2OperationWithRetryOnFailureAsync(
                        operation,
                        cacheOperation,
                        cacheKey,
                        bytes,
                        true).ConfigureAwait(false);
                }
            }
        }