Implement deferred WaitQueue, DiskAvailability, and NoOpCache behavior with tests
This commit is contained in:
@@ -153,15 +153,105 @@ public interface IOcspResponseCache
|
||||
void Remove(string key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runtime counters for OCSP response cache behavior.
|
||||
/// Mirrors Go <c>OCSPResponseCacheStats</c> shape.
|
||||
/// </summary>
|
||||
public sealed class OcspResponseCacheStats
|
||||
{
|
||||
public long Responses { get; set; }
|
||||
public long Hits { get; set; }
|
||||
public long Misses { get; set; }
|
||||
public long Revokes { get; set; }
|
||||
public long Goods { get; set; }
|
||||
public long Unknowns { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A no-op OCSP cache that never stores anything.
|
||||
/// Mirrors Go <c>NoOpCache</c> in server/ocsp_responsecache.go.
|
||||
/// </summary>
|
||||
internal sealed class NoOpCache : IOcspResponseCache
|
||||
{
|
||||
public byte[]? Get(string key) => null;
|
||||
public void Put(string key, byte[] response) { }
|
||||
public void Remove(string key) { }
|
||||
private readonly Lock _mu = new();
|
||||
private readonly OcspResponseCacheConfig _config;
|
||||
private OcspResponseCacheStats? _stats;
|
||||
private bool _online;
|
||||
|
||||
public NoOpCache()
|
||||
: this(new OcspResponseCacheConfig { Type = "none" })
|
||||
{
|
||||
}
|
||||
|
||||
public NoOpCache(OcspResponseCacheConfig config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public byte[]? Get(string key) => null;
|
||||
|
||||
public void Put(string key, byte[] response) { }
|
||||
|
||||
public void Remove(string key) => Delete(key);
|
||||
|
||||
public void Delete(string key)
|
||||
{
|
||||
_ = key;
|
||||
}
|
||||
|
||||
public void Start(NatsServer? server = null)
|
||||
{
|
||||
lock (_mu)
|
||||
{
|
||||
_stats = new OcspResponseCacheStats();
|
||||
_online = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop(NatsServer? server = null)
|
||||
{
|
||||
lock (_mu)
|
||||
{
|
||||
_online = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Online()
|
||||
{
|
||||
lock (_mu)
|
||||
{
|
||||
return _online;
|
||||
}
|
||||
}
|
||||
|
||||
public string Type() => "none";
|
||||
|
||||
public OcspResponseCacheConfig Config()
|
||||
{
|
||||
lock (_mu)
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
}
|
||||
|
||||
public OcspResponseCacheStats? Stats()
|
||||
{
|
||||
lock (_mu)
|
||||
{
|
||||
if (_stats is null)
|
||||
return null;
|
||||
|
||||
return new OcspResponseCacheStats
|
||||
{
|
||||
Responses = _stats.Responses,
|
||||
Hits = _stats.Hits,
|
||||
Misses = _stats.Misses,
|
||||
Revokes = _stats.Revokes,
|
||||
Goods = _stats.Goods,
|
||||
Unknowns = _stats.Unknowns,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user