Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions src/Components/Endpoints/src/CacheView/CacheViewKeyResolver.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Globalization;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Components.HotReload;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;

namespace Microsoft.AspNetCore.Components.Endpoints;

internal static class CacheViewKeyResolver
{
private static readonly ConcurrentDictionary<string, string[]> _sortedNamesByRawValue = new(StringComparer.Ordinal);

static CacheViewKeyResolver()
{
if (HotReloadManager.IsSupported)
{
HotReloadManager.Default.OnDeltaApplied += _sortedNamesByRawValue.Clear;
}
}

internal static string ComputeKey(CacheView cacheView, HttpContext httpContext)
{
using var hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
Expand Down Expand Up @@ -162,22 +150,21 @@ private static void AppendDelimitedCookieValues(IncrementalHash hash, string sep
AppendString(hash, ")");
}

private static string[] CollectSortedNames(string separatedValues)
=> _sortedNamesByRawValue.GetOrAdd(separatedValues, static raw =>
private static List<string> CollectSortedNames(string separatedValues)
{
var names = new List<string>();
foreach (var segment in separatedValues.AsSpan().Split(','))
{
var names = new List<string>();
foreach (var segment in raw.AsSpan().Split(','))
var name = separatedValues.AsSpan()[segment].Trim();
if (!name.IsEmpty)
{
var name = raw.AsSpan()[segment].Trim();
if (!name.IsEmpty)
{
names.Add(name.ToString());
}
names.Add(name.ToString());
}
}

names.Sort(StringComparer.Ordinal);
return names.ToArray();
});
names.Sort(StringComparer.Ordinal);
return names;
}

private static void AppendAllQueryValues(IncrementalHash hash, HttpRequest request)
{
Expand Down
Loading