Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#230 add in TFM's so dependencies can be optimised #231

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why targeting net3.1 explicitly since it's not supported anymore?
Honest question, I've never multi targeted like this before so I'm trying to better understand the TFMs selection strategy here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other comment, selecting net core 3.1 enables that framework and higher to benefit of not adding the dependency. Net 6 was for consistent but we could remove it if desired.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking right now at this as an inspiration and to double check.

There too I can see net6.0 in the <TargetFrameworks> element, even though below there are no conditions targeting that... I'm trying to wrap my head around this.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as above: why targeting net3.1 explicitly since it's not supported anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding net core 3.1 enables net 5 projects to also not have the dependency. Net 6 is to keep it consistent with the other location but could remove it as well,

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
thompson-tomo marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above about net3.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason i did the 3 frameworks was that System.Threading.Tasks.Extensions was added in netcoreapp 3.1 however System.Diagnostics.DiagnosticSource was only added in net 6.

Copy link
Collaborator

@jodydonetti jodydonetti Apr 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, but if System.Diagnostics.DiagnosticSource was only added in net 6, why its condition is "'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netcoreapp3.1'"?
I would've expected it has "'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net6.0'", or am I missing something?

Again, be patient, first time dealing with these kinds of issues 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, the reason for the condition being like this is so that it only adds the dependency when it wasn't a part of the framework. If we were to add net6.0 then it would be included.

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
Loading