/// <summary> /// 从磁盘本地读取缓存内容 /// </summary> private string LoadCacheContentFromDiskLocal(string name, string dataId, string group, string tenant) { string content = _localConfigInfoProcessor.GetFailover(name, dataId, group, tenant); if (string.IsNullOrEmpty(content)) { content = _localConfigInfoProcessor.GetSnapshot(name, dataId, group, tenant); } return(content); }
/// <summary> /// 校验本地缓存配置 /// </summary> private void CheckLocalConfig(CacheData cacheData) { string dataId = cacheData.DataId; string group = cacheData.Group; string tenant = cacheData.Tenant; string path = _localConfigInfoProcessor.GetFailoverPath(_agent.GetName(), dataId, group, tenant); if (!cacheData.IsUseLocalConfig && File.Exists(path)) { string content = _localConfigInfoProcessor.GetFailover(_agent.GetName(), dataId, group, tenant); string md5 = CacheData.GetMD5String(content); cacheData.IsUseLocalConfig = true; cacheData.LocalConfigLastModified = File.GetLastWriteTime(path).GetTimeStamp(); cacheData.Content = content; _logger.Warn($"[{_agent.GetName()}] [failover-change] failover file created. dataId={dataId}, group={group}, tenant={tenant}, md5={md5}, content={ContentUtils.TruncateContent(content)}"); return; } if (cacheData.IsUseLocalConfig && !File.Exists(path)) { cacheData.IsUseLocalConfig = false; _logger.Warn($"[{_agent.GetName()}] [failover-change] failover file deleted, dataId={dataId}, group={group}, tenant={tenant}"); return; } if (cacheData.IsUseLocalConfig && File.Exists(path) && cacheData.LocalConfigLastModified != File.GetLastWriteTime(path).GetTimeStamp()) { string content = _localConfigInfoProcessor.GetFailover(_agent.GetName(), dataId, group, tenant); string md5 = CacheData.GetMD5String(content); cacheData.IsUseLocalConfig = true; cacheData.LocalConfigLastModified = File.GetLastWriteTime(path).GetTimeStamp(); cacheData.Content = content; _logger.Warn($"[{_agent.GetName()}] [failover-change] failover file changed. dataId={dataId}, group={group}, tenant={tenant}, md5={md5}, content={ContentUtils.TruncateContent(content)}"); } }