diff --git a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs index 3f90cab019..db83cd073a 100644 --- a/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs +++ b/src/SignalR/common/SignalR.Common/src/Protocol/HandshakeProtocol.cs @@ -26,29 +26,24 @@ namespace Microsoft.AspNetCore.SignalR.Protocol private const string TypePropertyName = "type"; private static JsonEncodedText TypePropertyNameBytes = JsonEncodedText.Encode(TypePropertyName); - private static ConcurrentDictionary> _messageCache = new ConcurrentDictionary>(); + private static readonly ReadOnlyMemory _successHandshakeData; - public static ReadOnlySpan GetSuccessfulHandshake(IHubProtocol protocol) + static HandshakeProtocol() { - ReadOnlyMemory result; - if (!_messageCache.TryGetValue(protocol, out result)) + var memoryBufferWriter = MemoryBufferWriter.Get(); + try { - var memoryBufferWriter = MemoryBufferWriter.Get(); - try - { - WriteResponseMessage(HandshakeResponseMessage.Empty, memoryBufferWriter); - result = memoryBufferWriter.ToArray(); - _messageCache.TryAdd(protocol, result); - } - finally - { - MemoryBufferWriter.Return(memoryBufferWriter); - } + WriteResponseMessage(HandshakeResponseMessage.Empty, memoryBufferWriter); + _successHandshakeData = memoryBufferWriter.ToArray(); + } + finally + { + MemoryBufferWriter.Return(memoryBufferWriter); } - - return result.Span; } + public static ReadOnlySpan GetSuccessfulHandshake(IHubProtocol protocol) => _successHandshakeData.Span; + /// /// Writes the serialized representation of a to the specified writer. ///