mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-28 00:36:00 +00:00
Improve tests
This commit is contained in:
22
DiscordChatExporter.Cli.Tests/Utils/GlobalCache.cs
Normal file
22
DiscordChatExporter.Cli.Tests/Utils/GlobalCache.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordChatExporter.Cli.Tests.Utils
|
||||
{
|
||||
internal static class GlobalCache
|
||||
{
|
||||
private static readonly Dictionary<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user