From a67276252c8bfcd6b6c5344e70debc6d67d917a9 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 27 May 2023 00:39:49 +0200 Subject: Been a while since I last committed --- MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs') diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs index 4a00a8a..bd44f7f 100644 --- a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs @@ -5,6 +5,7 @@ namespace MatrixRoomUtils.Web.Classes; public partial class LocalStorageWrapper { + private static SemaphoreSlim _semaphoreSlim = new(1); public static Settings Settings { get; set; } = new(); //some basic logic @@ -15,6 +16,9 @@ public partial class LocalStorageWrapper } public static async Task LoadFromLocalStorage(ILocalStorageService localStorage) { + await _semaphoreSlim.WaitAsync(); + if (RuntimeCache.WasLoaded) return; + RuntimeCache.WasLoaded = true; Settings = await localStorage.GetItemAsync("rory.matrixroomutils.settings") ?? new(); //RuntimeCache stuff @@ -43,7 +47,8 @@ public partial class LocalStorageWrapper Console.WriteLine($"Loading generic cache entry {s}"); RuntimeCache.GenericResponseCache[s.Replace("rory.matrixroomutils.generic_cache:", "")] = await localStorage.GetItemAsync>(s); } - RuntimeCache.WasLoaded = true; + + _semaphoreSlim.Release(); } public static async Task SaveToLocalStorage(ILocalStorageService localStorage) @@ -70,7 +75,7 @@ public partial class LocalStorageWrapper if (key == "rory.matrixroomutils.user_cache") await localStorage.SetItemAsync(key, RuntimeCache.LoginSessions); if (key == "rory.matrixroomutils.last_used_token") await localStorage.SetItemAsync(key, RuntimeCache.LastUsedToken); if (key == "rory.matrixroomutils.homeserver_resolution_cache") await localStorage.SetItemAsync(key, RuntimeCache.HomeserverResolutionCache); - if (key == "rory.matrixroomutils.generic_cache") await localStorage.SetItemAsync(key, RuntimeCache.GenericResponseCache); + //if (key == "rory.matrixroomutils.generic_cache") await localStorage.SetItemAsync(key, RuntimeCache.GenericResponseCache); } } -- cgit 1.4.1