move classes around, name caches more consistently, add more caches
This commit is contained in:
parent
e86b37ce2a
commit
e17dcf90a1
30 changed files with 443 additions and 51 deletions
|
|
@ -1,26 +0,0 @@
|
|||
using System.Collections.Concurrent;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Rest.Core;
|
||||
|
||||
namespace Catalogger.Backend.Cache;
|
||||
|
||||
public class UserCacheService(IDiscordRestUserAPI userApi)
|
||||
{
|
||||
private readonly ConcurrentDictionary<Snowflake, IUser> _cache = new();
|
||||
|
||||
public int Size => _cache.Count;
|
||||
|
||||
public async Task<IUser?> GetUserAsync(Snowflake userId)
|
||||
{
|
||||
if (_cache.TryGetValue(userId, out var user)) return user;
|
||||
|
||||
var res = await userApi.GetUserAsync(userId);
|
||||
if (!res.IsSuccess) return null;
|
||||
|
||||
_cache[userId] = res.Entity;
|
||||
return res.Entity;
|
||||
}
|
||||
|
||||
public void UpdateUser(IUser user) => _cache[user.ID] = user;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue