Remove ConcurrentDictionary in HandshakeProtocol (#23315)
This commit is contained in:
parent
10baccefb4
commit
71af57fdc0
|
|
@ -26,29 +26,24 @@ namespace Microsoft.AspNetCore.SignalR.Protocol
|
||||||
private const string TypePropertyName = "type";
|
private const string TypePropertyName = "type";
|
||||||
private static JsonEncodedText TypePropertyNameBytes = JsonEncodedText.Encode(TypePropertyName);
|
private static JsonEncodedText TypePropertyNameBytes = JsonEncodedText.Encode(TypePropertyName);
|
||||||
|
|
||||||
private static ConcurrentDictionary<IHubProtocol, ReadOnlyMemory<byte>> _messageCache = new ConcurrentDictionary<IHubProtocol, ReadOnlyMemory<byte>>();
|
private static readonly ReadOnlyMemory<byte> _successHandshakeData;
|
||||||
|
|
||||||
public static ReadOnlySpan<byte> GetSuccessfulHandshake(IHubProtocol protocol)
|
static HandshakeProtocol()
|
||||||
{
|
{
|
||||||
ReadOnlyMemory<byte> result;
|
var memoryBufferWriter = MemoryBufferWriter.Get();
|
||||||
if (!_messageCache.TryGetValue(protocol, out result))
|
try
|
||||||
{
|
{
|
||||||
var memoryBufferWriter = MemoryBufferWriter.Get();
|
WriteResponseMessage(HandshakeResponseMessage.Empty, memoryBufferWriter);
|
||||||
try
|
_successHandshakeData = memoryBufferWriter.ToArray();
|
||||||
{
|
}
|
||||||
WriteResponseMessage(HandshakeResponseMessage.Empty, memoryBufferWriter);
|
finally
|
||||||
result = memoryBufferWriter.ToArray();
|
{
|
||||||
_messageCache.TryAdd(protocol, result);
|
MemoryBufferWriter.Return(memoryBufferWriter);
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
MemoryBufferWriter.Return(memoryBufferWriter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Span;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ReadOnlySpan<byte> GetSuccessfulHandshake(IHubProtocol protocol) => _successHandshakeData.Span;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the serialized representation of a <see cref="HandshakeRequestMessage"/> to the specified writer.
|
/// Writes the serialized representation of a <see cref="HandshakeRequestMessage"/> to the specified writer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue