From db4584c37380f1826986b3acfe35bbf92693dfc6 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 11 Mar 2023 02:04:31 -0500 Subject: Persistant cache abstraction and runtime loading --- .../src/BlobCacheTable.cs | 22 +++++++++++++++------- 1 file changed, 15 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 270cf1e..f3f1b50 100644 --- a/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs +++ b/lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs @@ -39,6 +39,7 @@ namespace VNLib.Data.Caching.ObjectCache { private readonly uint _tableSize; private readonly IBlobCacheBucket[] _buckets; + private readonly IPersistantCacheStore? _persistant; /// /// Initializes a new @@ -46,9 +47,10 @@ namespace VNLib.Data.Caching.ObjectCache /// The number of elements in each bucket /// The number of buckets within the table /// The heap used to allocate cache entry buffers from + /// An optional for persistant cache implementations /// /// - public BlobCacheTable(uint tableSize, uint bucketSize, IUnmangedHeap heap) + public BlobCacheTable(uint tableSize, uint bucketSize, IUnmangedHeap heap, IPersistantCacheStore? persistantCache) { _ = heap ?? throw new ArgumentNullException(nameof(heap)); @@ -61,16 +63,18 @@ namespace VNLib.Data.Caching.ObjectCache _tableSize = tableSize; _buckets = new IBlobCacheBucket[tableSize]; + _persistant = persistantCache; + //Init buckets - InitBuckets(tableSize, bucketSize, _buckets, heap); + InitBuckets(tableSize, bucketSize, _buckets, heap, persistantCache); } - private static void InitBuckets(uint size, uint bucketSize, IBlobCacheBucket[] table, IUnmangedHeap heap) + private static void InitBuckets(uint size, uint bucketSize, IBlobCacheBucket[] table, IUnmangedHeap heap, IPersistantCacheStore? persistantCache) { - for(int i = 0; i < size; i++) + for(uint i = 0; i < size; i++) { - table[i] = new BlobCacheBucket((int)bucketSize, heap); + table[i] = new BlobCacheBucket(i, (int)bucketSize, heap, persistantCache); } } @@ -118,8 +122,12 @@ namespace VNLib.Data.Caching.ObjectCache /// protected sealed override void Free() { - //Dispose buckets - Array.ForEach(_buckets, static b => b.Dispose()); + //Dispose persistance store + using (_persistant) + { + //Dispose buckets + Array.ForEach(_buckets, static b => b.Dispose()); + } } /// -- cgit