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/DataModel/EntityCacheExtensions.cs | 49 +++++++--------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs') 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; /// public override bool IsConnected { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => cache.IsConnected; + get => Cache.IsConnected; } /// protected override ICacheKeyGenerator KeyGen { get; } - public ScopedCacheImpl(IGlobalCacheProvider cache, ICacheKeyGenerator keyGen) - { - this.cache = cache; - KeyGen = keyGen; - } - /// - public override Task AddOrUpdateAsync(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; /// - public override Task 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; } /// - public override Task GetAsync(string key, CancellationToken cancellation) + public override Task 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(scoped, cancellation); + return Cache.DeleteAsync(scoped, cancellation); } /// @@ -201,7 +182,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel //Compute the key for the id string scoped = KeyGen.ComputedKey(key); - return cache.GetAsync(scoped, deserializer, cancellation); + return Cache.GetAsync(scoped, deserializer, cancellation); } /// @@ -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); } /// @@ -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); } /// @@ -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); } /// - public override object GetUnderlyingStore() => cache.GetUnderlyingStore(); + public override object GetUnderlyingStore() => Cache.GetUnderlyingStore(); } } -- cgit