From 3c353afe4dffa3da9c96ef25b02f0004676afe5f Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 14 Oct 2023 15:50:46 -0400 Subject: experimential expansion and performance changes --- .../src/BlobCacheTable.cs | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs') diff --git a/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs b/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs index f3f1b50..9443737 100644 --- a/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs +++ b/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs @@ -28,10 +28,10 @@ using System.Collections; using System.Collections.Generic; using VNLib.Utils; -using VNLib.Utils.Memory; namespace VNLib.Data.Caching.ObjectCache { + /// /// A concrete implementation of a /// @@ -41,18 +41,32 @@ namespace VNLib.Data.Caching.ObjectCache private readonly IBlobCacheBucket[] _buckets; private readonly IPersistantCacheStore? _persistant; + /// /// Initializes a new /// /// The number of elements in each bucket /// The number of buckets within the table - /// The heap used to allocate cache entry buffers from + /// A single cache memory manger to share across all buckets /// An optional for persistant cache implementations /// /// - public BlobCacheTable(uint tableSize, uint bucketSize, IUnmangedHeap heap, IPersistantCacheStore? persistantCache) + public BlobCacheTable(uint tableSize, uint bucketSize, ICacheEntryMemoryManager manager, IPersistantCacheStore? persistantCache) + :this(tableSize, bucketSize, new SharedMemManager(manager), persistantCache) + { } + + /// + /// Initializes a new + /// + /// The number of elements in each bucket + /// The number of buckets within the table + /// A factory that can generate bucket-local memory managers + /// An optional for persistant cache implementations + /// + /// + public BlobCacheTable(uint tableSize, uint bucketSize, ICacheMemoryManagerFactory factory, IPersistantCacheStore? persistantCache) { - _ = heap ?? throw new ArgumentNullException(nameof(heap)); + _ = factory ?? throw new ArgumentNullException(nameof(factory)); if(tableSize == 0) { @@ -66,15 +80,18 @@ namespace VNLib.Data.Caching.ObjectCache _persistant = persistantCache; //Init buckets - InitBuckets(tableSize, bucketSize, _buckets, heap, persistantCache); + InitBuckets(tableSize, bucketSize, _buckets, factory, persistantCache); } - private static void InitBuckets(uint size, uint bucketSize, IBlobCacheBucket[] table, IUnmangedHeap heap, IPersistantCacheStore? persistantCache) + private static void InitBuckets(uint size, uint bucketSize, IBlobCacheBucket[] table, ICacheMemoryManagerFactory man, IPersistantCacheStore? persistantCache) { for(uint i = 0; i < size; i++) { - table[i] = new BlobCacheBucket(i, (int)bucketSize, heap, persistantCache); + //Get the memory manager for the bucket + ICacheEntryMemoryManager manager = man.CreateForBucket(i); + + table[i] = new BlobCacheBucket(i, (int)bucketSize, manager, persistantCache); } } @@ -143,5 +160,12 @@ namespace VNLib.Data.Caching.ObjectCache Check(); return _buckets.AsEnumerable().GetEnumerator(); } + + private sealed record class SharedMemManager(ICacheEntryMemoryManager Manager) : ICacheMemoryManagerFactory + { + /// + public ICacheEntryMemoryManager CreateForBucket(uint bucketId) => Manager; + + } } } -- cgit