Repository: dotnet/aspnetcore
File: src/Middleware/OutputCaching/src/Memory/MemoryOutputCacheStore.cs (C#)

Code before:

        var entryId = Guid.NewGuid();

        if (tags != null)
        {
            // Lock with SetEntry() to prevent EvictByTagAsync() from trying to remove a tag whose entry hasn't been added yet.
            // It might be acceptable to not lock SetEntry() since in this case Remove(key) would just no-op and the user retry to evict.

            lock (_tagsLock)
            {
                foreach (var tag in tags)
                {
                    if (tag is null)
                    {
                        throw new ArgumentException(Resources.TagCannotBeNull);
                    }

                    if (!_taggedEntries.TryGetValue(tag, out var keys))
                    {
                        keys = new HashSet<(string, Guid)>();
                        _taggedEntries[tag] = keys;
                    }

                    Debug.Assert(keys != null);

                    keys.Add(ValueTuple.Create(key, entryId));
                }

                SetEntry(key, value, tags, validFor, entryId);
            }
        }
        else
        {
            SetEntry(key, value, tags, validFor, entryId);
        }

        return ValueTask.CompletedTask;
    }

    private void SetEntry(string key, byte[] value, string[]? tags, TimeSpan validFor, Guid entryId)
    {
        Debug.Assert(key != null);

        var options = new MemoryCacheEntryOptions
        {
            AbsoluteExpirationRelativeToNow = validFor,
            Size = value.Length
        };

        if (tags is { Length: > 0 })
        {

Review comment (suggestion):
```suggestion
                    keys.Add((key, entryId));
```
C# compiler does the right thing here.

Code after:

        var entryId = Guid.NewGuid();

        if (tags != null)
        {
            // Lock with SetEntry() to prevent EvictByTagAsync() from trying to remove a tag whose entry hasn't been added yet.
            // It might be acceptable to not lock SetEntry() since in this case Remove(key) would just no-op and the user retry to evict.

            lock (_tagsLock)
            {
                foreach (var tag in tags)
                {
                    if (tag is null)
                    {
                        throw new ArgumentException(Resources.TagCannotBeNull);
                    }

                    if (!_taggedEntries.TryGetValue(tag, out var keys))
                    {
                        keys = new HashSet<TaggedEntry>();
                        _taggedEntries[tag] = keys;
                    }

                    Debug.Assert(keys != null);

                    keys.Add(new TaggedEntry(key, entryId));
                }

                SetEntry(key, value, tags, validFor, entryId);
            }
        }
        else
        {
            SetEntry(key, value, tags, validFor, entryId);
        }

        return ValueTask.CompletedTask;
    }

    private void SetEntry(string key, byte[] value, string[]? tags, TimeSpan validFor, Guid entryId)
    {
        Debug.Assert(key != null);

        var options = new MemoryCacheEntryOptions
        {
            AbsoluteExpirationRelativeToNow = validFor,
            Size = value.Length
        };

        if (tags is { Length: > 0 })
        {