about summary refs log tree commit diff
path: root/LibMatrix/Interfaces/Services/IStorageProvider.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-04-07 17:34:48 +0200
committerRory& <root@rory.gay>2025-04-07 17:34:48 +0200
commit637279d9b761df32968e3c5af87ae34b8ade69cd (patch)
treefe0d1ec912343f81318933404443be84d12e42e0 /LibMatrix/Interfaces/Services/IStorageProvider.cs
parentFollowup documentation from chat, fix trailing whitespace (diff)
downloadLibMatrix-637279d9b761df32968e3c5af87ae34b8ade69cd.tar.xz
Intermediary commit: rewrite optimising of sync store, support compiled JSON in IStorageProvider
Diffstat (limited to '')
-rw-r--r--LibMatrix/Interfaces/Services/IStorageProvider.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/LibMatrix/Interfaces/Services/IStorageProvider.cs b/LibMatrix/Interfaces/Services/IStorageProvider.cs

index fb7bb6d..f7e5488 100644 --- a/LibMatrix/Interfaces/Services/IStorageProvider.cs +++ b/LibMatrix/Interfaces/Services/IStorageProvider.cs
@@ -1,3 +1,7 @@ +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; +using LibMatrix.Responses; + namespace LibMatrix.Interfaces.Services; public interface IStorageProvider { @@ -17,6 +21,13 @@ public interface IStorageProvider { Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, value)!"); throw new NotImplementedException(); } + + public Task SaveObjectAsync<T>(string key, T value, JsonTypeInfo<T> jsonTypeInfo) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObjectAsync<T>(key, value, typeInfo), using default implementation w/ MemoryStream!"); + var ms = new MemoryStream(); + JsonSerializer.Serialize(ms, value, jsonTypeInfo); + return SaveStreamAsync(key, ms); + } // load public Task<T?> LoadObjectAsync<T>(string key) { @@ -24,6 +35,12 @@ public interface IStorageProvider { throw new NotImplementedException(); } + public async Task<T?> LoadObjectAsync<T>(string key, JsonTypeInfo<T> jsonTypeInfo) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, typeInfo), using default implementation!"); + await using var stream = await LoadStreamAsync(key); + return JsonSerializer.Deserialize(stream!, jsonTypeInfo); + } + // check if exists public Task<bool> ObjectExistsAsync(string key) { Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement ObjectExists(key)!");