aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-02 21:35:08 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-02 21:35:08 -0400
commit718bed529299ea9aad03d848b835cbda1854be34 (patch)
tree5efa103be60cc512ba049bc5f9880d96faedf676 /lib
parentd2d812213b99ee17f9433f81871b694c4053ff23 (diff)
Remove ambiguous default serializer functions
Diffstat (limited to 'lib')
-rw-r--r--lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs28
-rw-r--r--lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs18
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs49
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs8
4 files changed, 51 insertions, 52 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
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs
index befa14a..bf2fa2a 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs
@@ -141,56 +141,37 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
private sealed class ScopedCacheImpl: ScopedCache
{
- private readonly IGlobalCacheProvider cache;
+ private readonly IGlobalCacheProvider Cache;
///<inheritdoc/>
public override bool IsConnected
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => cache.IsConnected;
+ get => Cache.IsConnected;
}
///<inheritdoc/>
protected override ICacheKeyGenerator KeyGen { get; }
- public ScopedCacheImpl(IGlobalCacheProvider cache, ICacheKeyGenerator keyGen)
- {
- this.cache = cache;
- KeyGen = keyGen;
- }
-
///<inheritdoc/>
- public override Task AddOrUpdateAsync<T>(string key, string? newKey, T value, CancellationToken cancellation)
- {
- _ = key ?? throw new ArgumentNullException(nameof(key));
-
- //Compute primary key from id
- string primary = KeyGen.ComputedKey(key);
-
- //If newkey exists, compute the secondary key
- string? secondary = newKey != null ? KeyGen.ComputedKey(newKey) : null;
-
- return cache.AddOrUpdateAsync(primary, secondary, value, cancellation);
- }
+ public override ICacheObjectDeserializer DefaultDeserializer => Cache.DefaultDeserializer;
///<inheritdoc/>
- public override Task<bool> DeleteAsync(string key, CancellationToken cancellation)
+ public override ICacheObjectSerializer DefaultSerializer => Cache.DefaultSerializer;
+
+ public ScopedCacheImpl(IGlobalCacheProvider cache, ICacheKeyGenerator keyGen)
{
- _ = key ?? throw new ArgumentNullException(nameof(key));
- //Compute the key for the id
- string scoped = KeyGen.ComputedKey(key);
- return cache.DeleteAsync(scoped, cancellation);
+ this.Cache = cache;
+ KeyGen = keyGen;
}
///<inheritdoc/>
- public override Task<T> GetAsync<T>(string key, CancellationToken cancellation)
+ public override Task<bool> DeleteAsync(string key, CancellationToken cancellation)
{
_ = key ?? throw new ArgumentNullException(nameof(key));
-
//Compute the key for the id
string scoped = KeyGen.ComputedKey(key);
-
- return cache.GetAsync<T?>(scoped, cancellation);
+ return Cache.DeleteAsync(scoped, cancellation);
}
///<inheritdoc/>
@@ -201,7 +182,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
//Compute the key for the id
string scoped = KeyGen.ComputedKey(key);
- return cache.GetAsync<T?>(scoped, deserializer, cancellation);
+ return Cache.GetAsync<T?>(scoped, deserializer, cancellation);
}
///<inheritdoc/>
@@ -215,7 +196,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
//If newkey exists, compute the secondary key
string? secondary = newKey != null ? KeyGen.ComputedKey(newKey) : null;
- return cache.AddOrUpdateAsync(primary, secondary, value, serialzer, cancellation);
+ return Cache.AddOrUpdateAsync(primary, secondary, value, serialzer, cancellation);
}
///<inheritdoc/>
@@ -226,7 +207,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
//Compute the key for the id
string scoped = KeyGen.ComputedKey(key);
- return cache.GetAsync(scoped, callback, state, cancellation);
+ return Cache.GetAsync(scoped, callback, state, cancellation);
}
///<inheritdoc/>
@@ -240,11 +221,11 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
//If newkey exists, compute the secondary key
string? secondary = newKey != null ? KeyGen.ComputedKey(newKey) : null;
- return cache.AddOrUpdateAsync(primary, secondary, callback, state, cancellation);
+ return Cache.AddOrUpdateAsync(primary, secondary, callback, state, cancellation);
}
///<inheritdoc/>
- public override object GetUnderlyingStore() => cache.GetUnderlyingStore();
+ public override object GetUnderlyingStore() => Cache.GetUnderlyingStore();
}
}
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs
index 6ad902d..545e194 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs
@@ -47,13 +47,13 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel
public abstract bool IsConnected { get; }
///<inheritdoc/>
- public abstract Task AddOrUpdateAsync<T>(string key, string? newKey, T value, CancellationToken cancellation);
+ public abstract ICacheObjectDeserializer DefaultDeserializer { get; }
///<inheritdoc/>
- public abstract Task<bool> DeleteAsync(string key, CancellationToken cancellation);
-
+ public abstract ICacheObjectSerializer DefaultSerializer { get; }
+
///<inheritdoc/>
- public abstract Task<T?> GetAsync<T>(string key, CancellationToken cancellation);
+ public abstract Task<bool> DeleteAsync(string key, CancellationToken cancellation);
///<inheritdoc/>
public abstract Task<T?> GetAsync<T>(string key, ICacheObjectDeserializer deserializer, CancellationToken cancellation);