From 6b87785026ca57d6f41cff87ddbd066362f3cacc Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 14 Feb 2024 14:23:53 -0500 Subject: Squashed commit of the following: commit 456ead9bc8b0f61357bae93152ad0403c4940101 Author: vnugent Date: Tue Feb 13 14:46:35 2024 -0500 fix: #1 shared cluster index on linux & latested core updates commit a481d63f964a5d5204cac2e95141f37f9a28d573 Author: vnugent Date: Tue Jan 23 15:43:50 2024 -0500 cache extension api tweaks --- .../src/DataModel/EntityCacheExtensions.cs | 21 +++++++++++---------- .../src/DataModel/ScopedCache.cs | 4 ++-- .../src/VNCacheExtensions.cs | 21 +++++++-------------- 3 files changed, 20 insertions(+), 26 deletions(-) (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src') diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs index 562c220..6b39580 100644 --- a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs +++ b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/EntityCacheExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.VNCache @@ -164,12 +164,13 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel /// The factory callback function to produce a value when a cache miss occurs /// A token to cancel the operation /// A task that completes by returning the entity + /// /// public static async Task GetOrLoadAsync(this IEntityCache cache, string id, Func> factory, CancellationToken cancellation = default) where T : class { - _ = cache ?? throw new ArgumentNullException(nameof(cache)); - _ = id ?? throw new ArgumentNullException(nameof(id)); - _ = factory ?? throw new ArgumentNullException(nameof(factory)); + ArgumentNullException.ThrowIfNull(cache); + ArgumentNullException.ThrowIfNull(factory); + ArgumentException.ThrowIfNullOrWhiteSpace(id); //try to load the value from cache T? record = await cache.GetAsync(id, cancellation); @@ -241,7 +242,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel /// public override Task DeleteAsync(string key, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); //Compute the key for the id string scoped = KeyGen.ComputedKey(key); return Cache.DeleteAsync(scoped, cancellation); @@ -250,7 +251,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel /// public override Task GetAsync(string key, ICacheObjectDeserializer deserializer, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); //Compute the key for the id string scoped = KeyGen.ComputedKey(key); @@ -261,7 +262,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel /// public override Task AddOrUpdateAsync(string key, string? newKey, T value, ICacheObjectSerializer serialzer, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); //Compute primary key from id string primary = KeyGen.ComputedKey(key); @@ -275,7 +276,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel /// public override Task GetAsync(string key, ObjectDataSet callback, T state, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); //Compute the key for the id string scoped = KeyGen.ComputedKey(key); @@ -284,9 +285,9 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel } /// - public override Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation) + public override Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); //Compute primary key from id string primary = KeyGen.ComputedKey(key); diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs index 545e194..5107dea 100644 --- a/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs +++ b/lib/VNLib.Plugins.Extensions.VNCache/src/DataModel/ScopedCache.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.VNCache @@ -65,7 +65,7 @@ namespace VNLib.Plugins.Extensions.VNCache.DataModel public abstract Task GetAsync(string key, ObjectDataSet callback, T state, CancellationToken cancellation); /// - public abstract Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation); + public abstract Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation); /// public abstract object GetUnderlyingStore(); diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/VNCacheExtensions.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/VNCacheExtensions.cs index d191ab1..c434e22 100644 --- a/lib/VNLib.Plugins.Extensions.VNCache/src/VNCacheExtensions.cs +++ b/lib/VNLib.Plugins.Extensions.VNCache/src/VNCacheExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.VNCache @@ -112,26 +112,19 @@ namespace VNLib.Plugins.Extensions.VNCache /// public static ScopedCache GetPrefixedCache(this IGlobalCacheProvider cache, string prefix, HashAlg digest = HashAlg.SHA1, HashEncodingMode encoding = HashEncodingMode.Base64) { - _ = cache ?? throw new ArgumentNullException(nameof(cache)); - _ = prefix ?? throw new ArgumentNullException(nameof(prefix)); + ArgumentNullException.ThrowIfNull(cache); + ArgumentException.ThrowIfNullOrEmpty(prefix); //Create simple cache key generator SimpleCacheKeyImpl keyProv = new(prefix, digest, encoding); //Create the scoped cache from the simple provider return cache.GetScopedCache(keyProv); } - private sealed class SimpleCacheKeyImpl : ICacheKeyGenerator + private sealed class SimpleCacheKeyImpl(string prefix, HashAlg digest, HashEncodingMode encoding) : ICacheKeyGenerator { - private readonly string Prefix; - private readonly HashAlg Digest; - private readonly HashEncodingMode Encoding; - - public SimpleCacheKeyImpl(string prefix, HashAlg digest, HashEncodingMode encoding) - { - Prefix = prefix; - Digest = digest; - Encoding = encoding; - } + private readonly string Prefix = prefix; + private readonly HashAlg Digest = digest; + private readonly HashEncodingMode Encoding = encoding; [MethodImpl(MethodImplOptions.AggressiveInlining)] private int ComputeBufferSize(string id) => id.Length + Prefix.Length; -- cgit