using Microsoft.Extensions.Caching.Distributed; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace BinaryDad.Coding { public static class Users { public static readonly IDictionary Sessions = new Dictionary(StringComparer.OrdinalIgnoreCase); } public class UserCache { private readonly IDistributedCache _cache; public UserCache(IDistributedCache cache) { _cache = cache; } public async Task GetUser(string connectionId) { var user = new User(); user.Id = connectionId; user.Name = await _cache.GetStringAsync($"name-{connectionId}"); user.Color = await _cache.GetStringAsync($"color-{connectionId}"); return user; } } }