aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.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/MemoryCacheConfig.cs
parentf56566feeeff0441ba8dd22e4ed755fab1ef7e11 (diff)
Expose public configuration api
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs48
1 files changed, 43 insertions, 5 deletions
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs
index bcd821b..f34ae91 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/MemoryCacheConfig.cs
@@ -25,24 +25,41 @@
using System;
using System.Text.Json.Serialization;
+using VNLib.Plugins.Extensions.Loading;
+
namespace VNLib.Plugins.Extensions.VNCache
{
- internal sealed class MemoryCacheConfig : ICacheRefreshPolicy
+ /// <summary>
+ /// Memorycache configuration object. Json-(de)serializable
+ /// </summary>
+ public sealed class MemoryCacheConfig : ICacheRefreshPolicy, IOnConfigValidation
{
+ /// <summary>
+ /// The number of buckets within the cache table
+ /// </summary>
[JsonPropertyName("buckets")]
public uint TableSize { get; set; } = 10;
+ /// <summary>
+ /// The number of cache entries within each bucket
+ /// </summary>
[JsonPropertyName("bucket_size")]
public uint BucketSize { get; set; } = 5000;
+ /// <summary>
+ /// The maxium size (in bytes) of each cache entry within any bucket
+ /// </summary>
[JsonPropertyName("max_object_size")]
public uint MaxBlobSize { get; set; } = 16 * 1024;
[JsonIgnore]
public TimeSpan MaxCacheAge { get; set; } = TimeSpan.FromMinutes(1);
+ /// <summary>
+ /// When refresh intervals are configured, The maxium cache entry age in seconds.
+ /// </summary>
[JsonPropertyName("max_age_sec")]
- public uint MaxAgeSec
+ public uint MaxAgeSeconds
{
get => (uint)MaxCacheAge.TotalSeconds;
set => MaxCacheAge = TimeSpan.FromSeconds(value);
@@ -50,16 +67,37 @@ namespace VNLib.Plugins.Extensions.VNCache
/*
* Default disable cache
*/
+ [JsonIgnore]
public TimeSpan RefreshInterval { get; set; } = TimeSpan.Zero;
+ /// <summary>
+ /// The time (in seconds) a cache entry refresh interval will occur
+ /// if scheduled on a plugin
+ /// </summary>
[JsonPropertyName("refresh_interval_sec")]
- public uint RefreshSec
+ public uint RefreshIntervalSeconds
{
get => (uint)RefreshInterval.TotalSeconds;
set => RefreshInterval = TimeSpan.FromSeconds(value);
}
- [JsonPropertyName("write_through")]
- public bool WriteThrough { get; set; } = true;
+ ///<inheritdoc/>
+ public void Validate()
+ {
+ if(TableSize == 0)
+ {
+ throw new ArgumentException("You must specify a cache bucket table size", "buckets");
+ }
+
+ if(BucketSize == 0)
+ {
+ throw new ArgumentException("You must specify the maxium number of entires allowed in each bucket ", "bucket_size");
+ }
+
+ if(MaxBlobSize < 16)
+ {
+ throw new ArgumentException("You must configure a maximum object size", "max_object_size");
+ }
+ }
}
} \ No newline at end of file