public async Task AddUserConnectionAsync(string userId, string connectionId, string sessionId) { string cacheKey = CacheKeyFactories.GenerateConnectionCacheKey(userId, EntityKey); ConnectionCacheModel model = new ConnectionCacheModel() { Connections = new Dictionary <string, string>() { { connectionId, sessionId } }, UserId = userId }; var connections = await connectionProvider.GetModelsBySearchPredicate(x => x.UserId == userId); if (connections.IsListNotNull()) { var connectionIdenteficators = new List <string>(); foreach (var connection in connections) { model.Connections.Add(connection.ConnectionId, connection.SessionId); } await CacheRemove(cacheKey); } await connectionProvider.CreateOrUpdateAsync(new Connection() { UserId = userId, Created = DateTime.Now, ConnectionId = connectionId, SessionId = sessionId }); await CacheSetString(cacheKey, model, TimeSpan.FromMinutes(tokenOptions.Value.AccessTokenLifeTime)); }