From a481d63f964a5d5204cac2e95141f37f9a28d573 Mon Sep 17 00:00:00 2001 From: vnugent Date: Tue, 23 Jan 2024 15:43:50 -0500 Subject: cache extension api tweaks --- .../src/BlobCacheExtensions.cs | 10 ++--- .../src/GlobalCacheExtensions.cs | 48 +++++++++++++++++++++- lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs | 44 ++++++++++++++++++-- .../src/DataModel/EntityCacheExtensions.cs | 21 +++++----- .../src/DataModel/ScopedCache.cs | 4 +- plugins/ObjectCacheServer/src/Cache/CacheStore.cs | 4 +- plugins/ObjectCacheServer/src/ICacheStore.cs | 4 +- .../src/RedisClientCacheEntry.cs | 14 ++++--- .../src/BucketLocalManagerFactory.cs | 36 +++++++++++----- .../src/FBMCacheClient.cs | 4 +- .../src/MemoryCache.cs | 4 +- .../src/RemoteBackedMemoryCache.cs | 14 +++---- .../src/VNCacheBase.cs | 4 +- .../src/VNCacheClient.cs | 4 +- 14 files changed, 157 insertions(+), 58 deletions(-) diff --git a/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheExtensions.cs b/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheExtensions.cs index ded89d2..4cacb3f 100644 --- a/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheExtensions.cs +++ b/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.ObjectCache @@ -144,14 +144,14 @@ namespace VNLib.Data.Caching.ObjectCache this IBlobCacheTable table, string objectId, string? alternateId, - ObjectDataReader bodyData, + ObjectDataGet bodyData, T state, DateTime time, CancellationToken cancellation = default) { - - _ = table ?? throw new ArgumentNullException(nameof(table)); - _ = bodyData ?? throw new ArgumentNullException(nameof(bodyData)); + ArgumentNullException.ThrowIfNull(table); + ArgumentNullException.ThrowIfNull(bodyData); + ArgumentException.ThrowIfNullOrWhiteSpace(objectId); //See if an id change is required if (string.IsNullOrWhiteSpace(alternateId)) diff --git a/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs b/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs index 586df73..203219c 100644 --- a/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs +++ b/lib/VNLib.Data.Caching/src/GlobalCacheExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching @@ -26,7 +26,8 @@ using System; using System.Threading; using System.Threading.Tasks; -#pragma warning disable CA1062 // Validate arguments of public methods +using VNLib.Net.Messaging.FBM; +using VNLib.Data.Caching.Exceptions; namespace VNLib.Data.Caching { @@ -46,6 +47,7 @@ namespace VNLib.Data.Caching /// A task that complets when the object data has been written to the data buffer public static Task GetAsync(this IGlobalCacheProvider cache, string key, IObjectData rawData, CancellationToken cancellation) { + ArgumentNullException.ThrowIfNull(cache); return cache.GetAsync(key, static (cd, data) => cd.SetData(data), rawData, cancellation); } @@ -61,6 +63,7 @@ namespace VNLib.Data.Caching /// A task that completes when the update operation has compelted public static Task AddOrUpdateAsync(this IGlobalCacheProvider cache, string key, string? newKey, IObjectData rawData, CancellationToken cancellation) { + ArgumentNullException.ThrowIfNull(cache); return cache.AddOrUpdateAsync(key, newKey, static cd => cd.GetData(), rawData, cancellation); } @@ -76,9 +79,48 @@ namespace VNLib.Data.Caching /// A task that completes when the update operation has compelted public static Task AddOrUpdateAsync(this IGlobalCacheProvider cache, string key, string? newKey, ReadOnlyMemory rawData, CancellationToken cancellation) { + ArgumentNullException.ThrowIfNull(cache); return cache.AddOrUpdateAsync(key, newKey, static cd => cd.Span, rawData, cancellation); } + /// + /// Gets an object from the server if it exists + /// + /// + /// + /// + /// The id of the object to get + /// A token to cancel the operation + /// A callback function that computes an object result from binary data + /// A user-state parameter to be passed back to the callback function + /// A task that completes to return the results of the response payload + /// + /// + /// + /// + /// + public static async Task GetAsync( + this IGlobalCacheProvider cache, + string objectId, + GetObjectFromData getter, + TState state, + CancellationToken cancellationToken = default + ) + { + ArgumentNullException.ThrowIfNull(cache); + ArgumentNullException.ThrowIfNull(getter); + + //Get state will store the object result if successfull get operation + GetObjectState st = new(state, getter); + + //Get the object, if successfull, compute the result + await cache.GetAsync(objectId, static (s, d) => s.ComputeResult(d), st, cancellationToken); + + //If the get operation failed, return a default value + return st.Result; + } + + /// /// Asynchronously gets a value from the backing cache store /// @@ -89,6 +131,7 @@ namespace VNLib.Data.Caching /// 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) { + ArgumentNullException.ThrowIfNull(cache); return cache.GetAsync(key, cache.DefaultDeserializer, cancellation); } @@ -104,6 +147,7 @@ namespace VNLib.Data.Caching /// 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) { + ArgumentNullException.ThrowIfNull(cache); return cache.AddOrUpdateAsync(key, newKey, value, cache.DefaultSerializer, cancellation); } } diff --git a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs index e04c9e4..1545b99 100644 --- a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs +++ b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching @@ -23,6 +23,7 @@ */ using System; +using System.Buffers; using System.Threading; using System.Threading.Tasks; @@ -39,12 +40,47 @@ namespace VNLib.Data.Caching public delegate void ObjectDataSet(T state, ReadOnlySpan objectData); /// - /// A delegate method that will get the raw objet data from a state object + /// A delegate method that will get the raw object data from a state object /// /// /// The state object passed to the caller /// The raw object data to store in cache - public delegate ReadOnlySpan ObjectDataReader(T state); + public delegate ReadOnlySpan ObjectDataGet(T state); + + /// + /// A delegate method that will write the raw object data to the supplied + /// data buffer + /// + /// + /// The state object passed to the caller + /// The finite sized buffer writer use to write object data to + public delegate void ObjectDataReader(T state, IBufferWriter finiteWriter); + + /// + /// A delegate method that will get an object from the raw object data + /// + /// + /// + /// Optional user-state data + /// The object data to compute the object result from + /// The resultant object + public delegate TObject GetObjectFromData(TState state, ReadOnlySpan data); + + /// + /// Internal structure used to store a callback and state for the + /// a data read/get operation on a cache object + /// + /// + /// The user-state object to pass + /// The data get callback function + internal readonly record struct ObjectDataGetState(T UserState, ObjectDataGet Getter); + + internal sealed class GetObjectState(TState State, GetObjectFromData Getter) + { + public T? Result; + + public void ComputeResult(ReadOnlySpan data) => Result = Getter(State, data); + } /// /// A global cache provider interface @@ -123,6 +159,6 @@ namespace VNLib.Data.Caching /// The callback state parameter /// A token to cancel the async operation /// A task that completes when the update operation has compelted - Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation); + Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation); } } \ No newline at end of file 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/plugins/ObjectCacheServer/src/Cache/CacheStore.cs b/plugins/ObjectCacheServer/src/Cache/CacheStore.cs index 02ed9b1..75abe37 100644 --- a/plugins/ObjectCacheServer/src/Cache/CacheStore.cs +++ b/plugins/ObjectCacheServer/src/Cache/CacheStore.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: ObjectCacheServer @@ -54,7 +54,7 @@ namespace VNLib.Data.Caching.ObjectCache.Server.Cache } /// - ValueTask ICacheStore.AddOrUpdateBlobAsync(string objectId, string? alternateId, ObjectDataReader bodyData, T state, CancellationToken token) + ValueTask ICacheStore.AddOrUpdateBlobAsync(string objectId, string? alternateId, ObjectDataGet bodyData, T state, CancellationToken token) { return Listener.Cache.AddOrUpdateObjectAsync(objectId, alternateId, bodyData, state, default, token); } diff --git a/plugins/ObjectCacheServer/src/ICacheStore.cs b/plugins/ObjectCacheServer/src/ICacheStore.cs index a638169..dcc9b6e 100644 --- a/plugins/ObjectCacheServer/src/ICacheStore.cs +++ b/plugins/ObjectCacheServer/src/ICacheStore.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: ObjectCacheServer @@ -38,7 +38,7 @@ namespace VNLib.Data.Caching.ObjectCache.Server /// The state parameter to pass to the data callback /// A token to cancel the async operation /// A value task that represents the async operation - ValueTask AddOrUpdateBlobAsync(string objectId, string? alternateId, ObjectDataReader bodyData, T state, CancellationToken token = default); + ValueTask AddOrUpdateBlobAsync(string objectId, string? alternateId, ObjectDataGet bodyData, T state, CancellationToken token = default); /// /// Clears all items from the store diff --git a/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs b/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs index f80c750..360be58 100644 --- a/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs +++ b/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs @@ -211,8 +211,8 @@ namespace VNLib.Data.Caching.Providers.Redis /// public async Task AddOrUpdateAsync(string key, string? newKey, T value, ICacheObjectSerializer serialzer, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); - _ = serialzer ?? throw new ArgumentNullException(nameof(serialzer)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); + ArgumentNullException.ThrowIfNull(serialzer); //Alloc update buffer using AddOrUpdateBuffer buffer = new(_defaultHeap, InitialWriterBufferSize, false); @@ -231,7 +231,7 @@ namespace VNLib.Data.Caching.Providers.Redis } /// - public async Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation) + public async Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation) { /* * Because the redis database only allows ReadonlyMemory when @@ -253,7 +253,7 @@ namespace VNLib.Data.Caching.Providers.Redis await _database.KeyRenameAsync(key, newKey); } - static IMemoryOwner AllocAndCopy(ObjectDataReader callback, T state, IUnmangedHeap heap, ref int length) + static IMemoryOwner AllocAndCopy(ObjectDataGet callback, T state, IUnmangedHeap heap, ref int length) { //Get the buffer from the callback ReadOnlySpan data = callback(state); @@ -276,7 +276,8 @@ namespace VNLib.Data.Caching.Providers.Redis /// public async Task GetAsync(string key, ICacheObjectDeserializer deserializer, CancellationToken cancellation) { - _ = deserializer ?? throw new ArgumentNullException(nameof(deserializer)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); + ArgumentNullException.ThrowIfNull(deserializer); //Try to get the value from the cache RedisValue value = await _database.StringGetAsync(key); @@ -293,7 +294,8 @@ namespace VNLib.Data.Caching.Providers.Redis /// public async Task GetAsync(string key, ObjectDataSet callback, T state, CancellationToken cancellation) { - _ = callback ?? throw new ArgumentNullException(nameof(callback)); + ArgumentException.ThrowIfNullOrWhiteSpace(key); + ArgumentNullException.ThrowIfNull(callback); //Try to get the value from the cache RedisValue value = await _database.StringGetAsync(key); diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/BucketLocalManagerFactory.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/BucketLocalManagerFactory.cs index 0f49849..793e9fe 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/BucketLocalManagerFactory.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/BucketLocalManagerFactory.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: ObjectCacheServer @@ -37,6 +37,22 @@ using VNLib.Plugins.Extensions.Loading; namespace VNLib.Data.Caching.Providers.VNCache { + /* + * How it works. + * + * The built-in object cache stores allow for a memory manager to be specified for + * each bucket. Since all operations on buckets are mutually exclusive, we can + * use a single heap for each bucket to get a little more performance on memory + * operations since no locking is required. + * + * This class may be called by a dependency injection container, or directly + * created calling the Create function. Configuration may specify allocation + * flags, currently only the zero all flag is supported. + * + * By default we just use the process global heap configuration to inizalize new + * private heap instances. + */ + [ConfigurationName("memory_manager", Required = false)] internal sealed class BucketLocalManagerFactory : VnDisposeable, ICacheMemoryManagerFactory { @@ -47,9 +63,9 @@ namespace VNLib.Data.Caching.Providers.VNCache public ICacheEntryMemoryManager CreateForBucket(uint bucketId) { //Init a new heap for a individual bucket - IUnmangedHeap localHeap = MemoryUtil.InitializeNewHeapForProcess(); + IUnmangedHeap localHeap = MemoryUtil.InitializeNewHeapForProcess(_zeroAll); - BucketLocalManager manager = new (localHeap, bucketId, _zeroAll); + BucketLocalManager manager = new (localHeap, bucketId); _managers.AddLast(manager); return manager; @@ -97,16 +113,16 @@ namespace VNLib.Data.Caching.Providers.VNCache * to get a little more performance on memory operations */ - private sealed record class BucketLocalManager(IUnmangedHeap Heap, uint BucketId, bool Zero) : ICacheEntryMemoryManager + private sealed record class BucketLocalManager(IUnmangedHeap Heap, uint BucketId) : ICacheEntryMemoryManager { /// - public object AllocHandle(uint size) => Heap.Alloc(size, Zero); + public object AllocHandle(uint size) => Heap.Alloc(size, false); /// public void FreeHandle(object handle) { - _ = handle ?? throw new ArgumentNullException(nameof(handle)); + ArgumentNullException.ThrowIfNull(handle); MemoryHandle _handle = Unsafe.As>(ref handle); //Free the handle @@ -116,7 +132,7 @@ namespace VNLib.Data.Caching.Providers.VNCache /// public uint GetHandleSize(object handle) { - _ = handle ?? throw new ArgumentNullException(nameof(handle)); + ArgumentNullException.ThrowIfNull(handle); MemoryHandle _handle = Unsafe.As>(ref handle); return (uint)_handle.Length; @@ -125,7 +141,7 @@ namespace VNLib.Data.Caching.Providers.VNCache /// public Span GetSpan(object handle, uint offset, uint length) { - _ = handle ?? throw new ArgumentNullException(nameof(handle)); + ArgumentNullException.ThrowIfNull(handle); MemoryHandle _handle = Unsafe.As>(ref handle); return _handle.GetOffsetSpan(offset, checked((int)length)); @@ -134,7 +150,7 @@ namespace VNLib.Data.Caching.Providers.VNCache /// public MemoryHandle PinHandle(object handle, int offset) { - _ = handle ?? throw new ArgumentNullException(nameof(handle)); + ArgumentNullException.ThrowIfNull(handle); MemoryHandle _handle = Unsafe.As>(ref handle); //Pin the handle @@ -144,7 +160,7 @@ namespace VNLib.Data.Caching.Providers.VNCache /// public void ResizeHandle(object handle, uint newSize) { - _ = handle ?? throw new ArgumentNullException(nameof(handle)); + ArgumentNullException.ThrowIfNull(handle); MemoryHandle _handle = Unsafe.As>(ref handle); //Resize the handle diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs index e21cf4a..73783dc 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/FBMCacheClient.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.Providers.VNCache @@ -317,7 +317,7 @@ namespace VNLib.Data.Caching.Providers.VNCache } /// - 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) { return !IsConnected ? throw new InvalidOperationException("The underlying client is not connected to a cache node") diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/MemoryCache.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/MemoryCache.cs index 98f6a3d..0c1a2b5 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/MemoryCache.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/MemoryCache.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.Providers.VNCache @@ -192,7 +192,7 @@ namespace VNLib.Data.Caching.Providers.VNCache } /// - 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) { //Update object data return _memCache.AddOrUpdateObjectAsync(key, newKey, callback, state, default, cancellation).AsTask(); diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/RemoteBackedMemoryCache.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/RemoteBackedMemoryCache.cs index c7952b4..ddc6c4b 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/RemoteBackedMemoryCache.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/RemoteBackedMemoryCache.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.Providers.VNCache @@ -83,8 +83,8 @@ namespace VNLib.Data.Caching.Providers.VNCache public RemoteBackedMemoryCache(MemoryCacheConfig memCache, IGlobalCacheProvider backingStore, BucketLocalManagerFactory? factory):base(memCache) { - _ = memCache ?? throw new ArgumentNullException(nameof(memCache)); - _ = backingStore ?? throw new ArgumentNullException(nameof(backingStore)); + ArgumentNullException.ThrowIfNull(memCache); + ArgumentNullException.ThrowIfNull(backingStore); memCache.Validate(); @@ -166,9 +166,9 @@ namespace VNLib.Data.Caching.Providers.VNCache /// public override async Task GetAsync(string key, ObjectDataSet setter, T state, CancellationToken cancellation) { - _ = key ?? throw new ArgumentNullException(nameof(key)); - _ = setter ?? throw new ArgumentNullException(nameof(setter)); - + ArgumentException.ThrowIfNullOrWhiteSpace(key); + ArgumentNullException.ThrowIfNull(setter); + CheckConnected(); IBlobCacheBucket bucket = _memCache.GetBucket(key); @@ -220,7 +220,7 @@ namespace VNLib.Data.Caching.Providers.VNCache } /// - public override async Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation) + public override async Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation) { CheckConnected(); diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheBase.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheBase.cs index f8a9ca6..c337ef4 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheBase.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheBase.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.Providers.VNCache @@ -49,7 +49,7 @@ namespace VNLib.Data.Caching.Providers.VNCache public abstract Task AddOrUpdateAsync(string key, string? newKey, T value, ICacheObjectSerializer serialzer, 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 Task DeleteAsync(string key, CancellationToken cancellation); diff --git a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheClient.cs b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheClient.cs index 9807939..20b9f69 100644 --- a/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheClient.cs +++ b/plugins/VNLib.Data.Caching.Providers.VNCache/src/VNCacheClient.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Data.Caching.Providers.VNCache @@ -173,7 +173,7 @@ namespace VNLib.Data.Caching.Providers.VNCache } /// - public Task AddOrUpdateAsync(string key, string? newKey, ObjectDataReader callback, T state, CancellationToken cancellation) + public Task AddOrUpdateAsync(string key, string? newKey, ObjectDataGet callback, T state, CancellationToken cancellation) { return _client.AddOrUpdateAsync(key, newKey, callback, state, cancellation); } -- cgit