diff options
author | vnugent <public@vaughnnugent.com> | 2023-03-11 02:04:31 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-03-11 02:04:31 -0500 |
commit | db4584c37380f1826986b3acfe35bbf92693dfc6 (patch) | |
tree | 3a264c95c6f3bf74453662cc8d180a9d570bfbfe /lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs | |
parent | a27a4ce58d6e09b34027b30d0c5c988e3112a54d (diff) |
Persistant cache abstraction and runtime loading
Diffstat (limited to 'lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs')
-rw-r--r-- | lib/VNLib.Data.Caching.ObjectCache/src/BlobCacheTable.cs | 22 |
1 files changed, 15 insertions, 7 deletions
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; /// <summary> /// Initializes a new <see cref="BlobCacheTable"/> @@ -46,9 +47,10 @@ namespace VNLib.Data.Caching.ObjectCache /// <param name="bucketSize">The number of elements in each bucket</param> /// <param name="tableSize">The number of buckets within the table</param> /// <param name="heap">The heap used to allocate cache entry buffers from</param> + /// <param name="persistantCache">An optional <see cref="IPersistantCacheStore"/> for persistant cache implementations</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> - 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 ///<inheritdoc/> 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()); + } } ///<inheritdoc/> |