示例#1
0
        private void SetMemoryEntry <TValue>(string operationId, string key, FusionCacheEntry <TValue> entry, FusionCacheEntryOptions options)
        {
            var memoryOptions = options.ToMemoryCacheEntryOptions();

            options.MemoryOptionsModifier?.Invoke(memoryOptions, entry.Value);

            if (_logger?.IsEnabled(LogLevel.Debug) ?? false)
            {
                _logger.LogDebug("FUSION (K={CacheKey} OP={CacheOperationId}): saving entry in memory {Options} {Entry}", key, operationId, memoryOptions.ToLogString(), entry.ToLogString());
            }

            _memoryCache.Set <FusionCacheEntry <TValue> >(key, entry, memoryOptions);
        }
示例#2
0
        private FusionCacheEntry <TValue>?MaybeGetFallbackEntry <TValue>(string operationId, string key, FusionCacheEntry <TValue>?distributedEntry, FusionCacheEntry <TValue>?memoryEntry, FusionCacheEntryOptions options, out bool failSafeActivated)
        {
            failSafeActivated = false;

            if (options.IsFailSafeEnabled)
            {
                if (_logger?.IsEnabled(LogLevel.Trace) ?? false)
                {
                    _logger.LogTrace("FUSION (K={CacheKey} OP={CacheOperationId}): trying to activate FAIL-SAFE", key, operationId);
                }
                if (distributedEntry is object)
                {
                    // FAIL SAFE (FROM DISTRIBUTED)
                    if (_logger?.IsEnabled(_options.FailSafeActivationLogLevel) ?? false)
                    {
                        _logger.Log(_options.FailSafeActivationLogLevel, "FUSION (K={CacheKey} OP={CacheOperationId}): FAIL-SAFE activated (from distributed)", key, operationId);
                    }
                    failSafeActivated = true;
                    return(distributedEntry);
                }
                else if (memoryEntry is object)
                {
                    // FAIL SAFE (FROM MEMORY)
                    if (_logger?.IsEnabled(_options.FailSafeActivationLogLevel) ?? false)
                    {
                        _logger.Log(_options.FailSafeActivationLogLevel, "FUSION (K={CacheKey} OP={CacheOperationId}): FAIL-SAFE activated (from memory)", key, operationId);
                    }
                    failSafeActivated = true;
                    return(memoryEntry);
                }
                else
                {
                    if (_logger?.IsEnabled(_options.FailSafeActivationLogLevel) ?? false)
                    {
                        _logger.Log(_options.FailSafeActivationLogLevel, "FUSION (K={CacheKey} OP={CacheOperationId}): unable to activate FAIL-SAFE (no entries in memory or distributed)", key, operationId);
                    }
                    return(null);
                }
            }
            else
            {
                if (_logger?.IsEnabled(LogLevel.Trace) ?? false)
                {
                    _logger.LogTrace("FUSION (K={CacheKey} OP={CacheOperationId}): FAIL-SAFE not enabled", key, operationId);
                }
                return(null);
            }
        }