From c4333d67e761c914f7e342cba279f85dba03d02a Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sun, 14 Apr 2024 09:18:47 +1000 Subject: [PATCH 1/4] #230 add in TFM's so dependencies can be optimised --- ...atures.FusionCache.Backplane.StackExchangeRedis.csproj | 5 ++++- ...res.FusionCache.Serialization.CysharpMemoryPack.csproj | 2 +- ...atures.FusionCache.Serialization.SystemTextJson.csproj | 4 ++-- src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs | 3 +-- .../ZiggyCreatures.FusionCache.csproj | 8 +++++++- 5 files changed, 15 insertions(+), 7 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 9446d1d7..aa3bcdaa 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 latest enable 1.0.0 @@ -28,6 +28,9 @@ + + + diff --git a/src/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack.csproj b/src/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack.csproj index 4b227c26..fab9a078 100644 --- a/src/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack.csproj +++ b/src/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack/ZiggyCreatures.FusionCache.Serialization.CysharpMemoryPack.csproj @@ -1,7 +1,7 @@  - netstandard2.1;net7.0 + netstandard2.1;net6.0 latest enable 1.0.0 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 87b0839d..431d83d7 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 latest enable 1.0.0 @@ -26,7 +26,7 @@ - + diff --git a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs index 3d83c9a8..43a02335 100644 --- a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs +++ b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs @@ -685,7 +685,7 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache // PHYSICAL DURATION TimeSpan physicalDuration; TimeSpan durationToUse; - TimeSpan failSafeMaxDurationToUse; + TimeSpan failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; bool incoherentFailSafeMaxDuration = false; durationToUse = DistributedCacheDuration ?? Duration; @@ -696,7 +696,6 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache } else { - failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; if (failSafeMaxDurationToUse < durationToUse) { incoherentFailSafeMaxDuration = true; diff --git a/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj b/src/ZiggyCreatures.FusionCache/ZiggyCreatures.FusionCache.csproj index f8366763..f74f19c6 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 latest enable 1.0.0 @@ -41,7 +41,13 @@ + + + + + + From 59a26a0434ffb590ec85a9395e6723ee0805d391 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sun, 21 Apr 2024 08:53:10 +1000 Subject: [PATCH 2/4] Switch to now have a default value --- src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs index 43a02335..3e3aa716 100644 --- a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs +++ b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs @@ -685,7 +685,7 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache // PHYSICAL DURATION TimeSpan physicalDuration; TimeSpan durationToUse; - TimeSpan failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; + TimeSpan failSafeMaxDurationToUse = TimeSpan.MaxValue; bool incoherentFailSafeMaxDuration = false; durationToUse = DistributedCacheDuration ?? Duration; @@ -696,6 +696,7 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache } else { + failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; if (failSafeMaxDurationToUse < durationToUse) { incoherentFailSafeMaxDuration = true; From 905b721f3ed2e07105ed7471a9c402241f74d200 Mon Sep 17 00:00:00 2001 From: Jody Donetti Date: Sun, 21 Apr 2024 11:51:06 +0200 Subject: [PATCH 3/4] Better incoherent fail-safe max duration logic --- .../FusionCacheEntryOptions.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs index 3e3aa716..5211e0ab 100644 --- a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs +++ b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs @@ -685,22 +685,26 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache // PHYSICAL DURATION TimeSpan physicalDuration; TimeSpan durationToUse; - TimeSpan failSafeMaxDurationToUse = TimeSpan.MaxValue; - bool incoherentFailSafeMaxDuration = false; + TimeSpan failSafeMaxDurationToUse; durationToUse = DistributedCacheDuration ?? Duration; if (IsFailSafeEnabled == false) { + // FAIL-SAFE DISABLED physicalDuration = durationToUse; } else { + // FAIL-SAFE ENABLED 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 +714,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; } From 5ac3465bf699a5b30d25a1bd5b67a139917b5f2f Mon Sep 17 00:00:00 2001 From: Jody Donetti Date: Sun, 21 Apr 2024 11:52:40 +0200 Subject: [PATCH 4/4] Even better incoherent fail-safe max duration handling logic (less allocation in happy path) --- src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs index 5211e0ab..eb5e3242 100644 --- a/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs +++ b/src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs @@ -685,7 +685,6 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache // PHYSICAL DURATION TimeSpan physicalDuration; TimeSpan durationToUse; - TimeSpan failSafeMaxDurationToUse; durationToUse = DistributedCacheDuration ?? Duration; @@ -697,7 +696,7 @@ internal DistributedCacheEntryOptions ToDistributedCacheEntryOptions(FusionCache else { // FAIL-SAFE ENABLED - failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; + var failSafeMaxDurationToUse = DistributedCacheFailSafeMaxDuration ?? FailSafeMaxDuration; if (failSafeMaxDurationToUse < durationToUse) { // INCOHERENT DURATION