aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Data.Caching
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNLib.Data.Caching')
-rw-r--r--lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs28
-rw-r--r--lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs18
2 files changed, 32 insertions, 14 deletions
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);
}
+
+ /// <summary>
+ /// Asynchronously gets a value from the backing cache store
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache"></param>
+ /// <param name="key">The key identifying the object to recover from cache</param>
+ /// <param name="cancellation">A token to cancel the async operation</param>
+ /// <returns>The value if found, or null if it does not exist in the store</returns>
+ public static Task<T?> GetAsync<T>(this IGlobalCacheProvider cache, string key, CancellationToken cancellation)
+ {
+ return cache.GetAsync<T>(key, cache.DefaultDeserializer, cancellation);
+ }
+
+ /// <summary>
+ /// Asynchronously sets (or updates) a cached value in the backing cache store
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="cache"></param>
+ /// <param name="key">The key identifying the object to recover from cache</param>
+ /// <param name="newKey">An optional key that will be changed for the new object</param>
+ /// <param name="cancellation">A token to cancel the async operation</param>
+ /// <param name="value">The value to set at the given key</param>
+ /// <returns>A task that completes when the update operation has compelted</returns>
+ public static Task AddOrUpdateAsync<T>(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();
/// <summary>
- /// Asynchronously gets a value from the backing cache store
+ /// Gets the default deserializer for the cache provider
/// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="key">The key identifying the object to recover from cache</param>
- /// <param name="cancellation">A token to cancel the async operation</param>
- /// <returns>The value if found, or null if it does not exist in the store</returns>
- Task<T?> GetAsync<T>(string key, CancellationToken cancellation);
+ ICacheObjectDeserializer DefaultDeserializer { get; }
/// <summary>
- /// Asynchronously sets (or updates) a cached value in the backing cache store
+ /// Gets the default serializer for the cache provider
/// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="key">The key identifying the object to recover from cache</param>
- /// <param name="newKey">An optional key that will be changed for the new object</param>
- /// <param name="cancellation">A token to cancel the async operation</param>
- /// <param name="value">The value to set at the given key</param>
- /// <returns>A task that completes when the update operation has compelted</returns>
- Task AddOrUpdateAsync<T>(string key, string? newKey, T value, CancellationToken cancellation);
+ ICacheObjectSerializer DefaultSerializer { get; }
/// <summary>
/// Asynchronously deletes an item from cache by its key