diff options
author | vnugent <public@vaughnnugent.com> | 2023-08-05 17:50:16 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-08-05 17:50:16 -0400 |
commit | bd4590d7cfaf2fa554ff6c37e095975ac4eb0f02 (patch) | |
tree | 66c4720e46cb7eb066a784a22a4de3544babbafb /lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs | |
parent | 6de8bb6b38b716605f0d275d998ca47e33520b7a (diff) |
Public prep, and api additions
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs')
-rw-r--r-- | lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCache.cs | 28 |
1 files changed, 28 insertions, 0 deletions
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; } + + ///<inheritdoc/> + 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()); + } + } + + ///<inheritdoc/> + 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 |