From 718bed529299ea9aad03d848b835cbda1854be34 Mon Sep 17 00:00:00 2001 From: vnugent Date: Thu, 2 Nov 2023 21:35:08 -0400 Subject: Remove ambiguous default serializer functions --- .../src/GlobalCacheExtensions.cs | 28 ++++++++++++++++++++++ lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs | 18 ++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'lib/VNLib.Data.Caching') diff --git a/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs b/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs index 8b23240..586df73 100644 --- a/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs +++ b/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs @@ -78,5 +78,33 @@ namespace VNLib.Data.Caching { return cache.AddOrUpdateAsync(key, newKey, static cd => cd.Span, rawData, cancellation); } + + /// + /// Asynchronously gets a value from the backing cache store + /// + /// + /// + /// The key identifying the object to recover from cache + /// A token to cancel the async operation + /// The value if found, or null if it does not exist in the store + public static Task GetAsync(this IGlobalCacheProvider cache, string key, CancellationToken cancellation) + { + return cache.GetAsync(key, cache.DefaultDeserializer, cancellation); + } + + /// + /// Asynchronously sets (or updates) a cached value in the backing cache store + /// + /// + /// + /// The key identifying the object to recover from cache + /// An optional key that will be changed for the new object + /// A token to cancel the async operation + /// The value to set at the given key + /// A task that completes when the update operation has compelted + public static Task AddOrUpdateAsync(this IGlobalCacheProvider cache, string key, string? newKey, T value, CancellationToken cancellation) + { + return cache.AddOrUpdateAsync(key, newKey, value, cache.DefaultSerializer, cancellation); + } } } \ No newline at end of file diff --git a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs index 18c8a98..e04c9e4 100644 --- a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs +++ b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs @@ -63,24 +63,14 @@ namespace VNLib.Data.Caching object GetUnderlyingStore(); /// - /// Asynchronously gets a value from the backing cache store + /// Gets the default deserializer for the cache provider /// - /// - /// The key identifying the object to recover from cache - /// A token to cancel the async operation - /// The value if found, or null if it does not exist in the store - Task GetAsync(string key, CancellationToken cancellation); + ICacheObjectDeserializer DefaultDeserializer { get; } /// - /// Asynchronously sets (or updates) a cached value in the backing cache store + /// Gets the default serializer for the cache provider /// - /// - /// The key identifying the object to recover from cache - /// An optional key that will be changed for the new object - /// A token to cancel the async operation - /// The value to set at the given key - /// A task that completes when the update operation has compelted - Task AddOrUpdateAsync(string key, string? newKey, T value, CancellationToken cancellation); + ICacheObjectSerializer DefaultSerializer { get; } /// /// Asynchronously deletes an item from cache by its key -- cgit