From bd4590d7cfaf2fa554ff6c37e095975ac4eb0f02 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 5 Aug 2023 17:50:16 -0400 Subject: Public prep, and api additions --- .../src/MemoryCache.cs | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs') diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs index a62b5db..e4c95a4 100644 --- a/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs +++ b/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs @@ -176,5 +176,33 @@ namespace VNLib.Plugins.Extensions.VNCache return default; } + + /// + public async Task GetAsync(string key, IObjectData rawData, CancellationToken cancellation) + { + Check(); + + //Get the bucket from the desired key + IBlobCacheBucket bucket = _memCache.GetBucket(key); + + //Obtain cache handle + using CacheBucketHandle handle = await bucket.WaitAsync(cancellation); + + //Try to read the value + if (handle.Cache.TryGetValue(key, out CacheEntry entry)) + { + //Set result data + rawData.SetData(entry.GetDataSegment()); + } + } + + /// + public Task AddOrUpdateAsync(string key, string? newKey, IObjectData rawData, ICacheObjectSerialzer serialzer, CancellationToken cancellation) + { + Check(); + + //Update object data + return _memCache.AddOrUpdateObjectAsync(key, newKey, static b => b.GetData(), rawData, default, cancellation).AsTask(); + } } } \ No newline at end of file -- cgit