mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 07:43:31 -07:00
22 lines
606 B
C#
22 lines
606 B
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DiscordChatExporter.Cli.Tests.Utils
|
|
{
|
|
internal static class GlobalCache
|
|
{
|
|
private static readonly ConcurrentDictionary<string, object?> Dictionary = new();
|
|
|
|
public static async Task<T> WrapAsync<T>(string key, Func<Task<T>> getAsync)
|
|
{
|
|
if (Dictionary.TryGetValue(key, out var value) && value is T existing)
|
|
return existing;
|
|
|
|
var result = await getAsync();
|
|
Dictionary[key] = result;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |