mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-12 05:08:58 +08:00
feat(config): 添加YAML配置文本校验器
- 实现同步和异步YAML文本校验功能 - 添加基于schema文件的配置校验支持 - 实现schema缓存机制避免重复磁盘IO - 提供配置表名称和文件路径参数验证 - 集成取消令牌支持异步操作取消 - 添加详细的异常处理和诊断信息
This commit is contained in:
parent
949904b57c
commit
774b69f560
@ -79,8 +79,9 @@ public static class YamlConfigTextValidator
|
||||
return cachedSchema;
|
||||
}
|
||||
|
||||
var lastWriteTimeUtc = File.GetLastWriteTimeUtc(schemaPath);
|
||||
var schema = YamlConfigSchemaValidator.Load(tableName, schemaPath);
|
||||
CacheSchema(cacheKey, schema);
|
||||
CacheSchema(cacheKey, lastWriteTimeUtc, schema);
|
||||
return schema;
|
||||
}
|
||||
|
||||
@ -104,9 +105,10 @@ public static class YamlConfigTextValidator
|
||||
return cachedSchema;
|
||||
}
|
||||
|
||||
var lastWriteTimeUtc = File.GetLastWriteTimeUtc(schemaPath);
|
||||
var schema = await YamlConfigSchemaValidator.LoadAsync(tableName, schemaPath, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
CacheSchema(cacheKey, schema);
|
||||
CacheSchema(cacheKey, lastWriteTimeUtc, schema);
|
||||
return schema;
|
||||
}
|
||||
|
||||
@ -157,15 +159,18 @@ public static class YamlConfigTextValidator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用最新的文件时间戳刷新 schema 缓存。
|
||||
/// 使用读取前捕获的文件时间戳刷新 schema 缓存。
|
||||
/// 这样即使 schema 在读取过程中发生变化,后续访问也会因时间戳变新而重新加载,
|
||||
/// 避免把“旧内容 + 新时间戳”写入缓存。
|
||||
/// </summary>
|
||||
/// <param name="cacheKey">缓存键。</param>
|
||||
/// <param name="lastWriteTimeUtc">本次读取开始前捕获的 schema 文件修改时间。</param>
|
||||
/// <param name="schema">最新加载的 schema。</param>
|
||||
private static void CacheSchema(
|
||||
SchemaCacheKey cacheKey,
|
||||
DateTime lastWriteTimeUtc,
|
||||
YamlConfigSchema schema)
|
||||
{
|
||||
var lastWriteTimeUtc = File.GetLastWriteTimeUtc(cacheKey.SchemaPath);
|
||||
SchemaCache[cacheKey] = new SchemaCacheEntry(lastWriteTimeUtc, schema);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user