From 85d599b1b7e2b589bcfc1ff7dd4473399a147486 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Mon, 22 Apr 2024 02:30:22 +1000 Subject: [PATCH] #230 add in TFM's so dependencies can be optimised (#231) * #230 add in TFM's so dependencies can be optimised * Better incoherent fail-safe max duration logic * Even better incoherent fail-safe max duration handling logic (less allocation in happy path) --------- Co-authored-by: Jody Donetti --- ...onCache.Backplane.StackExchangeRedis.csproj | 5 ++++- ...onCache.Serialization.SystemTextJson.csproj | 4 ++-- .../FusionCacheEntryOptions.cs | 18 +++++++----------- .../ZiggyCreatures.FusionCache.csproj | 8 +++++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis.csproj b/src/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis.csproj index c8060c47..6844296d 100644 --- a/src/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis.csproj +++ b/src/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis/ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp3.1;net6.0 1.0.0 ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis FusionCache backplane for Redis based on the StackExchange.Redis library @@ -24,6 +24,9 @@ + + + diff --git a/src/ZiggyCreatures.FusionCache.Serialization.SystemTextJson/ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj b/src/ZiggyCreatures.FusionCache.Serialization.SystemTextJson/ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj index 3a26a4ab..7cd6df56 100644 --- a/src/ZiggyCreatures.FusionCache.Serialization.SystemTextJson/ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj +++ b/src/ZiggyCreatures.FusionCache.Serialization.SystemTextJson/ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp3.1;net6.0 1.0.0 ZiggyCreatures.FusionCache.Serialization.SystemTextJson FusionCache serializer based on System.Text.Json @@ -22,7 +22,7 @@ - + diff --git a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs index 3d83c9a8..eb5e3242 100644 --- a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs +++ b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs @@ -685,22 +685,25 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache // PHYSICAL DURATION TimeSpan physicalDuration; TimeSpan durationToUse; - TimeSpan failSafeMaxDurationToUse; - bool incoherentFailSafeMaxDuration = false; durationToUse = DistributedCacheDuration ?? Duration; if (IsFailSafeEnabled == false) { + // FAIL-SAFE DISABLED physicalDuration = durationToUse; } else { - failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; + // FAIL-SAFE ENABLED + var failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; if (failSafeMaxDurationToUse < durationToUse) { - incoherentFailSafeMaxDuration = true; + // INCOHERENT DURATION physicalDuration = durationToUse; + + if (logger?.IsEnabled(options.IncoherentOptionsNormalizationLogLevel) ?? false) + logger.Log(options.IncoherentOptionsNormalizationLogLevel, "FUSION [N={CacheName} I={CacheInstanceId}] (O={CacheOperationId} K={CacheKey}): DistributedCacheFailSafeMaxDuration/FailSafeMaxDuration {FailSafeMaxDuration} was lower than the DistributedCacheDuration/Duration {Duration} on {Options} {MemoryOptions}. Duration has been used instead.", options.CacheName, options.InstanceId, operationId, key, failSafeMaxDurationToUse.ToLogString(), durationToUse.ToLogString(), this.ToLogString(), res.ToLogString()); } else { @@ -710,13 +713,6 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache res.AbsoluteExpiration = FusionCacheInternalUtils.GetNormalizedAbsoluteExpiration(physicalDuration, this, false); - // INCOHERENT DURATION - if (incoherentFailSafeMaxDuration) - { - if (logger?.IsEnabled(options.IncoherentOptionsNormalizationLogLevel) ?? false) - logger.Log(options.IncoherentOptionsNormalizationLogLevel, "FUSION [N={CacheName} I={CacheInstanceId}] (O={CacheOperationId} K={CacheKey}): DistributedCacheFailSafeMaxDuration/FailSafeMaxDuration {FailSafeMaxDuration} was lower than the DistributedCacheDuration/Duration {Duration} on {Options} {MemoryOptions}. Duration has been used instead.", options.CacheName, options.InstanceId, operationId, key, failSafeMaxDurationToUse.ToLogString(), durationToUse.ToLogString(), this.ToLogString(), res.ToLogString()); - } - return res; } diff --git a/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj b/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj index 26dcde36..17ba56f9 100644 --- a/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj +++ b/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0;netcoreapp3.1;net6.0 1.0.0 ZiggyCreatures.FusionCache FusionCache is an easy to use, fast and robust cache with advanced resiliency features and an optional distributed 2nd level. @@ -37,7 +37,13 @@ + + + + + +