22 lines
744 B
C#
22 lines
744 B
C#
using System.Collections.Concurrent;
|
|
using Remora.Discord.API.Abstractions.Objects;
|
|
using Remora.Rest.Core;
|
|
|
|
namespace Catalogger.Backend.Cache.InMemoryCache;
|
|
|
|
public class InMemoryInviteCache : IInviteCache
|
|
{
|
|
private readonly ConcurrentDictionary<Snowflake, IEnumerable<IInviteWithMetadata>> _invites =
|
|
new();
|
|
|
|
public Task<IEnumerable<IInviteWithMetadata>> TryGetAsync(Snowflake guildId) =>
|
|
_invites.TryGetValue(guildId, out var invites)
|
|
? Task.FromResult(invites)
|
|
: Task.FromResult<IEnumerable<IInviteWithMetadata>>([]);
|
|
|
|
public Task SetAsync(Snowflake guildId, IEnumerable<IInviteWithMetadata> invites)
|
|
{
|
|
_invites[guildId] = invites;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|