Skip to content

Commit

Permalink
#230 add in TFM's so dependencies can be optimised (#231)
Browse files Browse the repository at this point in the history
* #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 <[email protected]>
  • Loading branch information
thompson-tomo and jodydonetti authored Apr 21, 2024
1 parent a573ffe commit 85d599b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
<Version>1.0.0</Version>
<PackageId>ZiggyCreatures.FusionCache.Backplane.StackExchangeRedis</PackageId>
<Description>FusionCache backplane for Redis based on the StackExchange.Redis library</Description>
Expand All @@ -24,6 +24,9 @@

<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.7.27" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
<Version>1.0.0</Version>
<PackageId>ZiggyCreatures.FusionCache.Serialization.SystemTextJson</PackageId>
<Description>FusionCache serializer based on System.Text.Json</Description>
Expand All @@ -22,7 +22,7 @@
<ProjectReference Include="..\ZiggyCreatures.FusionCache\ZiggyCreatures.FusionCache.csproj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Json" Version="8.0.2" />
</ItemGroup>

Expand Down
18 changes: 7 additions & 11 deletions src/ZiggyCreatures.FusionCache/FusionCacheEntryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
<Version>1.0.0</Version>
<PackageId>ZiggyCreatures.FusionCache</PackageId>
<Description>FusionCache is an easy to use, fast and robust cache with advanced resiliency features and an optional distributed 2nd level.</Description>
Expand Down Expand Up @@ -37,7 +37,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

Expand Down

0 comments on commit 85d599b

Please sign in to comment.