2025-12-30 18:08:20 -06:00
|
|
|
using LANCommander.SDK.Models;
|
2025-01-23 00:25:11 -06:00
|
|
|
using ZiggyCreatures.Caching.Fusion;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.Server.Services.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class CacheExtensions
|
|
|
|
|
{
|
2025-12-23 21:12:06 -06:00
|
|
|
private static string GetThreadParticipantCacheKey(Guid threadId) => $"Chat/Thread/{threadId}/Participants";
|
2025-12-30 18:08:20 -06:00
|
|
|
private static string GetThreadCacheKey(Guid threadId) => $"Chat/Thread/{threadId}";
|
2025-12-23 21:12:06 -06:00
|
|
|
|
2025-02-23 08:49:43 -06:00
|
|
|
public static async Task ExpireGameCacheAsync(this IFusionCache cache)
|
|
|
|
|
{
|
|
|
|
|
await cache.RemoveByTagAsync(["Games", "Depot"]);
|
|
|
|
|
}
|
2025-01-23 00:25:11 -06:00
|
|
|
public static async Task ExpireGameCacheAsync(this IFusionCache cache, Guid? gameId)
|
|
|
|
|
{
|
|
|
|
|
if (gameId.HasValue)
|
2025-05-17 06:38:14 +02:00
|
|
|
await cache.RemoveByTagAsync([
|
|
|
|
|
$"Games/{gameId}",
|
|
|
|
|
"Games",
|
|
|
|
|
"Depot",
|
|
|
|
|
$"Games/{gameId}/Archives",
|
|
|
|
|
]);
|
2025-02-22 00:26:54 -06:00
|
|
|
else
|
|
|
|
|
await cache.RemoveByTagAsync(["Games", "Depot"]);
|
2025-01-23 00:25:11 -06:00
|
|
|
}
|
2025-05-17 06:38:14 +02:00
|
|
|
|
|
|
|
|
public static Task ExpireArchiveCacheAsync(this IFusionCache cache)
|
|
|
|
|
{
|
|
|
|
|
return ExpireArchiveCacheAsync(cache, archiveId: null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task ExpireArchiveCacheAsync(this IFusionCache cache, Guid? archiveId)
|
|
|
|
|
{
|
|
|
|
|
if (archiveId.HasValue)
|
|
|
|
|
await cache.RemoveByTagAsync([$"Archives/{archiveId}"]);
|
|
|
|
|
else
|
|
|
|
|
await cache.RemoveByTagAsync(["Archives"]);
|
|
|
|
|
}
|
2025-12-23 21:12:06 -06:00
|
|
|
|
2025-12-30 18:08:20 -06:00
|
|
|
public static async Task<ChatThread?> GetChatThreadAsync(this IFusionCache cache, Guid threadId)
|
|
|
|
|
{
|
|
|
|
|
var thread = await cache.TryGetAsync<ChatThread>(GetThreadCacheKey(threadId));
|
|
|
|
|
|
|
|
|
|
return thread.GetValueOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task SetChatThreadAsync(this IFusionCache cache, Guid threadId, ChatThread thread)
|
|
|
|
|
=> await cache.SetAsync(GetThreadCacheKey(threadId), thread);
|
|
|
|
|
|
2025-12-23 21:12:06 -06:00
|
|
|
public static async Task<List<string>> GetChatThreadParticipants(this IFusionCache cache, Guid threadId)
|
|
|
|
|
{
|
|
|
|
|
var participants = await cache.TryGetAsync<List<string>>(GetThreadParticipantCacheKey(threadId));
|
|
|
|
|
|
|
|
|
|
return participants.HasValue ? participants.Value : [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task SetChatThreadParticipants(this IFusionCache cache, Guid threadId,
|
|
|
|
|
List<string> participants)
|
|
|
|
|
=> await cache.SetAsync(GetThreadParticipantCacheKey(threadId), participants);
|
2025-01-23 00:25:11 -06:00
|
|
|
}
|