From f143c8cd3adc23a8f4473fc7cea7d1c58322233b Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 23 May 2023 17:19:17 +0200 Subject: idk --- MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs') diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs index c224160..4a00a8a 100644 --- a/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs +++ b/MatrixRoomUtils.Web/Classes/LocalStorageWrapper.cs @@ -16,6 +16,12 @@ public partial class LocalStorageWrapper public static async Task LoadFromLocalStorage(ILocalStorageService localStorage) { Settings = await localStorage.GetItemAsync("rory.matrixroomutils.settings") ?? new(); + + //RuntimeCache stuff + async void Save() => await SaveToLocalStorage(localStorage); + + RuntimeCache.Save = Save; + RuntimeCache.SaveObject = async (key, obj) => await localStorage.SetItemAsync(key, obj); // RuntimeCache.AccessToken = await localStorage.GetItemAsync("rory.matrixroomutils.token"); RuntimeCache.LastUsedToken = await localStorage.GetItemAsync("rory.matrixroomutils.last_used_token"); // RuntimeCache.CurrentHomeserver = await localStorage.GetItemAsync("rory.matrixroomutils.current_homeserver"); @@ -31,6 +37,12 @@ public partial class LocalStorageWrapper Console.WriteLine("Created authenticated home server"); } RuntimeCache.GenericResponseCache = await localStorage.GetItemAsync>>("rory.matrixroomutils.generic_cache") ?? new(); + + foreach (var s in (await localStorage.KeysAsync()).Where(x=>x.StartsWith("rory.matrixroomutils.generic_cache:")).ToList()) + { + Console.WriteLine($"Loading generic cache entry {s}"); + RuntimeCache.GenericResponseCache[s.Replace("rory.matrixroomutils.generic_cache:", "")] = await localStorage.GetItemAsync>(s); + } RuntimeCache.WasLoaded = true; } @@ -45,6 +57,10 @@ public partial class LocalStorageWrapper RuntimeCache.HomeserverResolutionCache.DistinctBy(x => x.Key) .ToDictionary(x => x.Key, x => x.Value)); await localStorage.SetItemAsync("rory.matrixroomutils.generic_cache", RuntimeCache.GenericResponseCache); + // foreach (var s in RuntimeCache.GenericResponseCache.Keys) + // { + // await localStorage.SetItemAsync($"rory.matrixroomutils.generic_cache:{s}", RuntimeCache.GenericResponseCache[s]); + // } } public static async Task SaveFieldToLocalStorage(ILocalStorageService localStorage, string key) { @@ -55,7 +71,6 @@ public partial class LocalStorageWrapper 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); - } } -- cgit 1.4.1