aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-04-08 16:43:02 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-04-08 16:43:02 -0400
commita866d831efc95900de2326f09531a54a65f18ea2 (patch)
treee61350d7bd831311bc5180bcf00e95a4401b9113 /lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
parentf56566feeeff0441ba8dd22e4ed755fab1ef7e11 (diff)
Expose public configuration api
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs35
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
index fb0e9e2..ffe9108 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
@@ -42,6 +42,16 @@ using VNLib.Plugins.Extensions.Loading.Events;
namespace VNLib.Plugins.Extensions.VNCache
{
+ /*
+ * A combinaed cache object that uses the blob cache data structures
+ * from the ObjectCache server library to implement similar memory cache
+ * features. All update operations are write-through operations, and a timer
+ * may be scheduled to refresh memorycache against the server (eventually)
+ *
+ * Memory cache is destroyed when the connection to the cache server is
+ * lost or is exiting
+ */
+
[ConfigurationName(VNCacheExtensions.CACHE_CONFIG_KEY)]
internal sealed class RemoteBackedMemoryCache : VnCacheClient, IIntervalScheduleable
{
@@ -53,10 +63,14 @@ namespace VNLib.Plugins.Extensions.VNCache
public RemoteBackedMemoryCache(PluginBase plugin, IConfigScope config) : base(plugin, config)
{
//Get nested memory cache config
- MemoryCacheConfig memCacheConfig = config[VNCacheExtensions.MEMORY_CACHE_CONFIG_KEY].Deserialize<MemoryCacheConfig>()!;
+ MemoryCacheConfig? memCacheConfig = config[VNCacheExtensions.MEMORY_CACHE_CONFIG_KEY].Deserialize<MemoryCacheConfig>();
+
+ _ = memCacheConfig ?? throw new ArgumentNullException(VNCacheExtensions.MEMORY_CACHE_CONFIG_KEY, "Missing required memory configuration variable");
+
+ memCacheConfig.Validate();
//Setup cache table
- _memCache = new BlobCacheTable(memCacheConfig.TableSize, memCacheConfig.BucketSize, Client.Config.BufferHeap ?? MemoryUtil.Shared, null);
+ _memCache = new BlobCacheTable(memCacheConfig.TableSize, memCacheConfig.BucketSize, Client.Config.BufferHeap, null);
_cacheConfig = memCacheConfig;
@@ -76,6 +90,23 @@ namespace VNLib.Plugins.Extensions.VNCache
}
}
+ public RemoteBackedMemoryCache(VnCacheClientConfig client, MemoryCacheConfig memCache, ILogProvider? debugLog):base(client, debugLog)
+ {
+ //Setup mem cache table
+ _memCache = new BlobCacheTable(memCache.TableSize, memCache.BucketSize, Client.Config.BufferHeap, null);
+
+ _cacheConfig = memCache;
+
+ /*
+ * Default to json serialization by using the default
+ * serializer and JSON options
+ */
+
+ JsonCacheObjectSerializer defaultSerializer = new();
+ _serialzer = defaultSerializer;
+ _deserialzer = defaultSerializer;
+ }
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CheckConnected()
{