From a825cd9fe7d517b10a4e8dd1c397389c9508e120 Mon Sep 17 00:00:00 2001 From: Mark Cilia Vincenti Date: Tue, 30 Dec 2025 19:50:43 +0100 Subject: [PATCH 1/2] Locking improvements --- EasyFortniteStats-ImageApi.csproj | 2 +- SharedAssets.cs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/EasyFortniteStats-ImageApi.csproj b/EasyFortniteStats-ImageApi.csproj index 26291db..4e8239b 100644 --- a/EasyFortniteStats-ImageApi.csproj +++ b/EasyFortniteStats-ImageApi.csproj @@ -10,7 +10,7 @@ - + diff --git a/SharedAssets.cs b/SharedAssets.cs index 796ebb1..a62cd11 100644 --- a/SharedAssets.cs +++ b/SharedAssets.cs @@ -1,4 +1,5 @@ using System.Runtime.InteropServices; +using AsyncKeyedLock; using Microsoft.Extensions.Caching.Memory; using SkiaSharp; @@ -7,7 +8,7 @@ namespace EasyFortniteStats_ImageApi; public class SharedAssets(IMemoryCache memoryCache) { private static readonly MemoryCacheEntryOptions CacheOptions = new() { Priority = CacheItemPriority.NeverRemove }; - private static readonly SemaphoreSlim Semaphore = new(1); + private static readonly AsyncNonKeyedLocker Semaphore = new(1); public async ValueTask GetBitmap(string format, string? arg1) { @@ -24,26 +25,23 @@ public class SharedAssets(IMemoryCache memoryCache) var cached = memoryCache.Get(key); if (cached is not null) return cached; - await Semaphore.WaitAsync(); + using var _ = await Semaphore.LockAsync(); cached = memoryCache.Get(key); if (cached is not null) { - Semaphore.Release(); return cached; } if (!File.Exists(path)) { memoryCache.Set(key, (SKBitmap?)null, CacheOptions); - Semaphore.Release(); return null; } using var data = await ReadToSkData(path); var bitmap = SKBitmap.Decode(data); memoryCache.Set(key, bitmap, CacheOptions); - Semaphore.Release(); return bitmap; } @@ -53,19 +51,17 @@ public async ValueTask GetFont(string path) var cached = memoryCache.Get(key); if (cached is not null) return cached; - await Semaphore.WaitAsync(); + using var _ = await Semaphore.LockAsync(); cached = memoryCache.Get(key); if (cached is not null) { - Semaphore.Release(); return cached; } using var data = await ReadToSkData(path); var typeface = SKTypeface.FromData(data); memoryCache.Set(key, typeface, CacheOptions); - Semaphore.Release(); return typeface; } From 866e410d7e2a7f3ae26ccd816e7f26c94905bba8 Mon Sep 17 00:00:00 2001 From: Mark Cilia Vincenti Date: Fri, 2 Jan 2026 10:17:48 +0100 Subject: [PATCH 2/2] Upgrade AsyncKeyedLock package to version 8.0.0 --- EasyFortniteStats-ImageApi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EasyFortniteStats-ImageApi.csproj b/EasyFortniteStats-ImageApi.csproj index 4e8239b..076166d 100644 --- a/EasyFortniteStats-ImageApi.csproj +++ b/EasyFortniteStats-ImageApi.csproj @@ -10,7 +10,7 @@ - +