Skip to content

Commit 0221d3e

Browse files
committed
Upgrade to .NET 9x
1 parent 5b16024 commit 0221d3e

File tree

45 files changed

+509
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+509
-574
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ dotnet_diagnostic.S127.severity = suggestion
99
dotnet_diagnostic.S2857.severity = suggestion
1010
dotnet_diagnostic.S2094.severity = suggestion
1111
dotnet_diagnostic.CA2227.severity = suggestion
12+
1213
dotnet_diagnostic.IDE0055.severity = none
14+
dotnet_diagnostic.IDE0160.severity = none
15+
dotnet_diagnostic.IDE0022.severity = none
16+
dotnet_diagnostic.IDE0021.severity = none
17+
dotnet_diagnostic.IDE0008.severity = none
18+
dotnet_diagnostic.IDE0058.severity = suggestion
19+
dotnet_diagnostic.IDE0046.severity = suggestion
20+
dotnet_diagnostic.IDE0048.severity = suggestion
21+
dotnet_diagnostic.IDE0010.severity = suggestion
22+
dotnet_diagnostic.IDE0045.severity = suggestion
23+
1324

1425
# CA1510: Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
1526
dotnet_diagnostic.CA1510.severity = suggestion

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup .NET Core
1313
uses: actions/setup-dotnet@v3
1414
with:
15-
dotnet-version: 8.0.x
15+
dotnet-version: 9.0.x
1616
- name: Build EFCoreSecondLevelCacheInterceptor lib
1717
run: dotnet build ./src/EFCoreSecondLevelCacheInterceptor/EFCoreSecondLevelCacheInterceptor.csproj --configuration Release
1818

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Setup .NET
6767
uses: actions/setup-dotnet@v3
6868
with:
69-
dotnet-version: 8.0.x
69+
dotnet-version: 9.0.x
7070
- name: Build
7171
run: dotnet build --configuration Release
7272

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.400",
3+
"version": "9.0.100",
44
"rollForward": "latestMajor",
55
"allowPrerelease": true
66
}

src/EFCoreSecondLevelCacheInterceptor/CacheSpecificQueriesOptions.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ namespace EFCoreSecondLevelCacheInterceptor;
66
/// <summary>
77
/// CacheAllQueries Options
88
/// </summary>
9-
public class CacheSpecificQueriesOptions : CacheAllQueriesOptions
9+
/// <remarks>
10+
/// CacheAllQueries Options
11+
/// </remarks>
12+
public class CacheSpecificQueriesOptions(IList<Type>? entityTypes) : CacheAllQueriesOptions
1013
{
11-
/// <summary>
12-
/// CacheAllQueries Options
13-
/// </summary>
14-
public CacheSpecificQueriesOptions(IList<Type>? entityTypes) => EntityTypes = entityTypes;
15-
1614
/// <summary>
1715
/// Given entity types to cache
1816
/// </summary>
19-
public IList<Type>? EntityTypes { get; }
17+
public IList<Type>? EntityTypes { get; } = entityTypes;
2018

2119
/// <summary>
2220
/// How should we determine which tables should be cached?

src/EFCoreSecondLevelCacheInterceptor/DbCommandInterceptorProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public T ProcessExecutingCommands<T>(DbCommand command, DbContext? context, T re
236236

237237
var efCacheKey = _cacheKeyProvider.GetEFCacheKey(command, context, cachePolicy);
238238

239-
if (!(_cacheService.GetValue(efCacheKey, cachePolicy) is EFCachedData cacheResult))
239+
if (_cacheService.GetValue(efCacheKey, cachePolicy) is not { } cacheResult)
240240
{
241241
if (_logger.IsLoggerEnabled)
242242
{

src/EFCoreSecondLevelCacheInterceptor/EFCacheKey.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ namespace EFCoreSecondLevelCacheInterceptor;
66
/// <summary>
77
/// Stores information of the computed key of the input LINQ query.
88
/// </summary>
9-
public class EFCacheKey
9+
/// <remarks>
10+
/// Stores information of the computed key of the input LINQ query.
11+
/// </remarks>
12+
public class EFCacheKey(ISet<string> cacheDependencies)
1013
{
11-
/// <summary>
12-
/// Stores information of the computed key of the input LINQ query.
13-
/// </summary>
14-
public EFCacheKey(ISet<string> cacheDependencies) => CacheDependencies = cacheDependencies;
15-
1614
/// <summary>
1715
/// Hash of the input LINQ query's computed key.
1816
/// </summary>
@@ -27,7 +25,7 @@ public class EFCacheKey
2725
/// Determines which entities are used in this LINQ query.
2826
/// This array will be used to invalidate the related cache of all related queries automatically.
2927
/// </summary>
30-
public ISet<string> CacheDependencies { get; }
28+
public ISet<string> CacheDependencies { get; } = cacheDependencies;
3129

3230
/// <summary>
3331
/// Equals
@@ -40,7 +38,8 @@ public override bool Equals(object? obj)
4038
return false;
4139
}
4240

43-
return string.Equals(KeyHash, efCacheKey.KeyHash, StringComparison.Ordinal) && DbContext == efCacheKey.DbContext;
41+
return string.Equals(KeyHash, efCacheKey.KeyHash, StringComparison.Ordinal) &&
42+
DbContext == efCacheKey.DbContext;
4443
}
4544

4645
/// <summary>
@@ -51,13 +50,15 @@ public override int GetHashCode()
5150
unchecked
5251
{
5352
var hash = 17;
54-
return hash * 23 + KeyHash.GetHashCode(StringComparison.Ordinal) + (DbContext == null ? 0 : DbContext.Name.GetHashCode(StringComparison.Ordinal));
53+
54+
return hash * 23 + KeyHash.GetHashCode(StringComparison.Ordinal) +
55+
(DbContext == null ? 0 : DbContext.Name.GetHashCode(StringComparison.Ordinal));
5556
}
5657
}
5758

5859
/// <summary>
5960
/// ToString
6061
/// </summary>
61-
public override string ToString() =>
62-
$"KeyHash: {KeyHash}, DbContext: {DbContext?.Name}, CacheDependencies: {string.Join(", ", CacheDependencies)}.";
62+
public override string ToString()
63+
=> $"KeyHash: {KeyHash}, DbContext: {DbContext?.Name}, CacheDependencies: {string.Join(separator: ", ", CacheDependencies)}.";
6364
}

src/EFCoreSecondLevelCacheInterceptor/EFCacheKeyProvider.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Text;
44
using Microsoft.EntityFrameworkCore;
55
using Microsoft.Extensions.Logging;
6-
using Microsoft.Extensions.Options;
7-
#if NET5_0 || NET6_0 || NET7_0 || NET8_0
6+
#if NET9_0 || NET5_0 || NET6_0 || NET7_0 || NET8_0
87
using System.Text.Json;
8+
using Microsoft.Extensions.Options;
99

1010
#else
1111
using System.Collections;
@@ -19,7 +19,7 @@ namespace EFCoreSecondLevelCacheInterceptor;
1919
/// </summary>
2020
public class EFCacheKeyProvider : IEFCacheKeyProvider
2121
{
22-
#if NET5_0 || NET6_0 || NET7_0 || NET8_0
22+
#if NET9_0 || NET5_0 || NET6_0 || NET7_0 || NET8_0
2323
private readonly EFCoreSecondLevelCacheSettings _settings;
2424
#endif
2525

@@ -40,7 +40,7 @@ public EFCacheKeyProvider(IEFCacheDependenciesProcessor cacheDependenciesProcess
4040
ILogger<EFCacheKeyProvider> keyProviderLogger,
4141
IEFHashProvider hashProvider,
4242
IEFCacheKeyPrefixProvider cacheKeyPrefixProvider
43-
#if NET5_0 || NET6_0 || NET7_0 || NET8_0
43+
#if NET9_0 || NET5_0 || NET6_0 || NET7_0 || NET8_0
4444
,
4545
IOptions<EFCoreSecondLevelCacheSettings> cacheSettings
4646
#endif
@@ -52,7 +52,7 @@ IOptions<EFCoreSecondLevelCacheSettings> cacheSettings
5252
_cachePolicyParser = cachePolicyParser;
5353
_hashProvider = hashProvider ?? throw new ArgumentNullException(nameof(hashProvider));
5454
_cacheKeyPrefixProvider = cacheKeyPrefixProvider;
55-
#if NET5_0 || NET6_0 || NET7_0 || NET8_0
55+
#if NET9_0 || NET5_0 || NET6_0 || NET7_0 || NET8_0
5656
_settings = cacheSettings?.Value ?? throw new ArgumentNullException(nameof(cacheSettings));
5757
#endif
5858
}
@@ -81,7 +81,7 @@ public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePol
8181
throw new ArgumentNullException(nameof(cachePolicy));
8282
}
8383

84-
var cacheKey = getCacheKey(command, cachePolicy.CacheSaltKey);
84+
var cacheKey = GetCacheKey(command, cachePolicy.CacheSaltKey);
8585
var cacheKeyPrefix = _cacheKeyPrefixProvider.GetCacheKeyPrefix();
8686

8787
var cacheKeyHash = !string.IsNullOrEmpty(cacheKeyPrefix)
@@ -94,8 +94,8 @@ public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePol
9494
if (_logger.IsLoggerEnabled)
9595
{
9696
_keyProviderLogger.LogDebug(
97-
"KeyHash: {CacheKeyHash}, DbContext: {Name}, CacheDependencies: {Dependencies}.", cacheKeyHash,
98-
cacheDbContextType?.Name, string.Join(", ", cacheDependencies));
97+
message: "KeyHash: {CacheKeyHash}, DbContext: {Name}, CacheDependencies: {Dependencies}.", cacheKeyHash,
98+
cacheDbContextType?.Name, string.Join(separator: ", ", cacheDependencies));
9999
}
100100

101101
return new EFCacheKey(cacheDependencies)
@@ -105,12 +105,12 @@ public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePol
105105
};
106106
}
107107

108-
private string getCacheKey(DbCommand command, string saltKey)
108+
private string GetCacheKey(DbCommand command, string saltKey)
109109
{
110110
var cacheKey = new StringBuilder();
111111
cacheKey.AppendLine(_cachePolicyParser.RemoveEFCachePolicyTag(command.CommandText));
112112

113-
cacheKey.AppendLine("ConnectionString").Append('=').Append(command.Connection?.ConnectionString);
113+
cacheKey.AppendLine(value: "ConnectionString").Append(value: '=').Append(command.Connection?.ConnectionString);
114114

115115
foreach (DbParameter? parameter in command.Parameters)
116116
{
@@ -120,33 +120,33 @@ private string getCacheKey(DbCommand command, string saltKey)
120120
}
121121

122122
cacheKey.Append(parameter.ParameterName)
123-
.Append('=')
123+
.Append(value: '=')
124124
.Append(GetParameterValue(parameter))
125-
.Append(',')
126-
.Append("Size")
127-
.Append('=')
125+
.Append(value: ',')
126+
.Append(value: "Size")
127+
.Append(value: '=')
128128
.Append(parameter.Size)
129-
.Append(',')
130-
.Append("Precision")
131-
.Append('=')
129+
.Append(value: ',')
130+
.Append(value: "Precision")
131+
.Append(value: '=')
132132
.Append(parameter.Precision)
133-
.Append(',')
134-
.Append("Scale")
135-
.Append('=')
133+
.Append(value: ',')
134+
.Append(value: "Scale")
135+
.Append(value: '=')
136136
.Append(parameter.Scale)
137-
.Append(',')
138-
.Append("Direction")
139-
.Append('=')
137+
.Append(value: ',')
138+
.Append(value: "Direction")
139+
.Append(value: '=')
140140
.Append(parameter.Direction)
141-
.Append(',');
141+
.Append(value: ',');
142142
}
143143

144-
cacheKey.AppendLine("SaltKey").Append('=').Append(saltKey);
144+
cacheKey.AppendLine(value: "SaltKey").Append(value: '=').Append(saltKey);
145145

146146
return cacheKey.ToString().Trim();
147147
}
148148

149-
#if NET5_0 || NET6_0 || NET7_0 || NET8_0
149+
#if NET9_0 || NET5_0 || NET6_0 || NET7_0 || NET8_0
150150
private string? GetParameterValue(DbParameter parameter)
151151
=> _settings.JsonSerializerOptions is null
152152
? JsonSerializer.Serialize(parameter.Value)

src/EFCoreSecondLevelCacheInterceptor/EFCacheManagerCoreProvider.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,10 @@ public void InsertValue(EFCacheKey cacheKey, EFCachedData value, EFCachePolicy c
5353
throw new ArgumentNullException(nameof(cacheKey));
5454
}
5555

56-
if (value == null)
56+
value ??= new EFCachedData
5757
{
58-
value = new EFCachedData
59-
{
60-
IsNull = true
61-
};
62-
}
58+
IsNull = true
59+
};
6360

6461
var keyHash = cacheKey.KeyHash;
6562

src/EFCoreSecondLevelCacheInterceptor/EFCachePolicyParser.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public string RemoveEFCachePolicyTag(string commandText)
9494

9595
var additionalNewlineIndex = commandText.IndexOf(value: '\n', endIndex + 1) - endIndex;
9696

97-
if (additionalNewlineIndex == 1 || additionalNewlineIndex == 2)
97+
if (additionalNewlineIndex is 1 or 2)
9898
{
9999
// EF's TagWith(..) method inserts an additional line break between
100100
// comments which we can remove as well
@@ -197,7 +197,7 @@ private bool ShouldCacheQueriesContainingTableTypes(string commandText,
197197
switch (options.TableTypeComparison)
198198
{
199199
case TableTypeComparison.Contains:
200-
if (queryEntityTypes.Any(entityType => options.EntityTypes.Contains(entityType)))
200+
if (queryEntityTypes.Any(options.EntityTypes.Contains))
201201
{
202202
return true;
203203
}
@@ -219,7 +219,7 @@ private bool ShouldCacheQueriesContainingTableTypes(string commandText,
219219

220220
break;
221221
case TableTypeComparison.ContainsOnly:
222-
if (queryEntityTypes.All(x => options.EntityTypes.Contains(x)))
222+
if (queryEntityTypes.All(options.EntityTypes.Contains))
223223
{
224224
return true;
225225
}
@@ -255,7 +255,7 @@ private bool ShouldCacheQueriesContainingTableNames(string commandText, CacheSpe
255255
switch (options.TableNameComparison)
256256
{
257257
case TableNameComparison.Contains:
258-
if (options.TableNames.Any(tableName => commandTableNames.Contains(tableName)))
258+
if (options.TableNames.Any(commandTableNames.Contains))
259259
{
260260
return true;
261261
}
@@ -342,7 +342,7 @@ private bool ShouldCacheQueriesContainingTableNames(string commandText, CacheSpe
342342
{
343343
var commandTableNames = _sqlCommandsProcessor.GetSqlCommandTableNames(commandText);
344344

345-
if (options.TableNames.Any(tableName => commandTableNames.Contains(tableName)))
345+
if (options.TableNames.Any(commandTableNames.Contains))
346346
{
347347
shouldBeCached = false;
348348
}
@@ -352,7 +352,7 @@ private bool ShouldCacheQueriesContainingTableNames(string commandText, CacheSpe
352352
{
353353
var queryEntityTypes = _sqlCommandsProcessor.GetSqlCommandEntityTypes(commandText, allEntityTypes);
354354

355-
if (queryEntityTypes.Any(entityType => options.EntityTypes.Contains(entityType)))
355+
if (queryEntityTypes.Any(options.EntityTypes.Contains))
356356
{
357357
shouldBeCached = false;
358358
}
@@ -387,21 +387,15 @@ private bool ShouldCacheQueriesContainingTableNames(string commandText, CacheSpe
387387
.First(textLine => textLine.StartsWith(EFCachePolicyTagPrefix, StringComparison.Ordinal))
388388
.Trim();
389389

390-
var parts = efCachePolicyCommentLine.Split(new[]
391-
{
392-
EFCachePolicy.PartsSeparator
393-
}, StringSplitOptions.RemoveEmptyEntries);
390+
var parts = efCachePolicyCommentLine.Split([EFCachePolicy.PartsSeparator],
391+
StringSplitOptions.RemoveEmptyEntries);
394392

395393
if (parts.Length != 2)
396394
{
397395
return null;
398396
}
399397

400-
var options = parts[1]
401-
.Split(new[]
402-
{
403-
EFCachePolicy.ItemsSeparator
404-
}, StringSplitOptions.None);
398+
var options = parts[1].Split([EFCachePolicy.ItemsSeparator], StringSplitOptions.None);
405399

406400
if (options.Length < 2)
407401
{
@@ -421,11 +415,7 @@ private bool ShouldCacheQueriesContainingTableNames(string commandText, CacheSpe
421415
var saltKey = options.Length >= 3 ? options[2] : string.Empty;
422416

423417
var cacheDependencies = options.Length >= 4
424-
? options[3]
425-
.Split(new[]
426-
{
427-
EFCachePolicy.CacheDependenciesSeparator
428-
}, StringSplitOptions.RemoveEmptyEntries)
418+
? options[3].Split([EFCachePolicy.CacheDependenciesSeparator], StringSplitOptions.RemoveEmptyEntries)
429419
: [];
430420

431421
var isDefaultCacheableMethod = options.Length >= 5 && bool.Parse(options[4]);

0 commit comments

Comments
 (0)