Coding/BinaryDad.Coding/Users.cs
2024-01-17 21:49:23 -05:00

35 lines
871 B
C#

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<string, User> Sessions = new Dictionary<string, User>(StringComparer.OrdinalIgnoreCase);
}
public class UserCache
{
private readonly IDistributedCache _cache;
public UserCache(IDistributedCache cache)
{
_cache = cache;
}
public async Task<User> 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;
}
}
}