Skip to content

Commit 305d676

Browse files
committed
Using named ValueTuples
1 parent bc8b059 commit 305d676

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.OutputCaching.Memory;
1010
internal sealed class MemoryOutputCacheStore : IOutputCacheStore
1111
{
1212
private readonly MemoryCache _cache;
13-
private readonly Dictionary<string, HashSet<ValueTuple<string,Guid>>> _taggedEntries = [];
13+
private readonly Dictionary<string, HashSet<(string key, Guid entryId)>> _taggedEntries = [];
1414
private readonly object _tagsLock = new();
1515

1616
internal MemoryOutputCacheStore(MemoryCache cache)
@@ -21,7 +21,7 @@ internal MemoryOutputCacheStore(MemoryCache cache)
2121
}
2222

2323
// For testing
24-
internal Dictionary<string, HashSet<string>> TaggedEntries => _taggedEntries.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Select(t => t.Item1).ToHashSet());
24+
internal Dictionary<string, HashSet<string>> TaggedEntries => _taggedEntries.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Select(t => t.key).ToHashSet());
2525

2626
public ValueTask EvictByTagAsync(string tag, CancellationToken cancellationToken)
2727
{
@@ -43,7 +43,7 @@ public ValueTask EvictByTagAsync(string tag, CancellationToken cancellationToken
4343
var oldCount = keys.Count;
4444
foreach (var tuple in keys)
4545
{
46-
_cache.Remove(tuple.Item1);
46+
_cache.Remove(tuple.key);
4747
i--;
4848
if (oldCount != keys.Count)
4949
{
@@ -93,7 +93,7 @@ public ValueTask SetAsync(string key, byte[] value, string[]? tags, TimeSpan val
9393

9494
if (!_taggedEntries.TryGetValue(tag, out var keys))
9595
{
96-
keys = new HashSet<ValueTuple<string, Guid>>();
96+
keys = new HashSet<(string, Guid)>();
9797
_taggedEntries[tag] = keys;
9898
}
9999

@@ -123,7 +123,7 @@ private void SetEntry(string key, byte[] value, string[]? tags, TimeSpan validFo
123123
Size = value.Length
124124
};
125125

126-
if (tags != null && tags.Length > 0)
126+
if (tags is { Length: > 0 })
127127
{
128128
// Remove cache keys from tag lists when the entry is evicted
129129
options.RegisterPostEvictionCallback(RemoveFromTags, ValueTuple.Create(tags, entryId));
@@ -136,9 +136,9 @@ void RemoveFromTags(object key, object? value, EvictionReason reason, object? st
136136
{
137137
Debug.Assert(state != null);
138138

139-
var stateTuple = (ValueTuple<string[], Guid>) state;
140-
string[] tags = stateTuple.Item1;
141-
Guid entryId = stateTuple.Item2;
139+
var stateTuple = ((string[] tags, Guid entryId))state;
140+
var tags = stateTuple.tags;
141+
var entryId = stateTuple.entryId;
142142

143143
Debug.Assert(tags != null);
144144
Debug.Assert(tags.Length > 0);
@@ -150,7 +150,7 @@ void RemoveFromTags(object key, object? value, EvictionReason reason, object? st
150150
{
151151
if (_taggedEntries.TryGetValue(tag, out var tagged))
152152
{
153-
tagged.Remove(ValueTuple.Create((string) key, entryId));
153+
tagged.Remove((key: (string)key, entryId));
154154

155155
// Remove the collection if there is no more keys in it
156156
if (tagged.Count == 0)

0 commit comments

Comments
 (0)