LANCommander/LANCommander.Server.Services/Extensions/CacheExtensions.cs
Pat Hartl e1c1469614 Fix chat component rendering
- Load thread after creation
- Change thread list from DataList to Flex
- Move unread badge to right side of chat thread list item
- Fix avatar rerendering after another message is added to message group
- Add styling to thread list
- Change message input to support markdown and add markdown rendering for message contents
2025-12-30 18:08:20 -06:00

61 lines
No EOL
2.2 KiB
C#

using LANCommander.SDK.Models;
using ZiggyCreatures.Caching.Fusion;
namespace LANCommander.Server.Services.Extensions;
public static class CacheExtensions
{
private static string GetThreadParticipantCacheKey(Guid threadId) => $"Chat/Thread/{threadId}/Participants";
private static string GetThreadCacheKey(Guid threadId) => $"Chat/Thread/{threadId}";
public static async Task ExpireGameCacheAsync(this IFusionCache cache)
{
await cache.RemoveByTagAsync(["Games", "Depot"]);
}
public static async Task ExpireGameCacheAsync(this IFusionCache cache, Guid? gameId)
{
if (gameId.HasValue)
await cache.RemoveByTagAsync([
$"Games/{gameId}",
"Games",
"Depot",
$"Games/{gameId}/Archives",
]);
else
await cache.RemoveByTagAsync(["Games", "Depot"]);
}
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"]);
}
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);
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);
}