fix read config cache (#600)

This commit is contained in:
binbin.zhang 2023-04-01 13:05:36 +08:00 committed by GitHub
parent c11cbcc5ca
commit dfbe390d78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -205,14 +205,20 @@ func (client *ConfigClient) getConfigInner(param vo.ConfigParam) (content string
response, err := client.configProxy.queryConfig(param.DataId, param.Group, clientConfig.NamespaceId,
clientConfig.TimeoutMs, false, client)
if err != nil {
logger.Infof("get config from server error:%v ", err)
logger.Errorf("get config from server error:%v, dataId=%s, group=%s, namespaceId=%s", err,
param.DataId, param.Group, clientConfig.NamespaceId)
if clientConfig.DisableUseSnapShot {
return "", errors.Errorf("get config from remote nacos server fail, and is not allowed to read local file, err:%v", err)
}
cacheContent, cacheErr := cache.ReadConfigFromFile(cacheKey, client.configCacheDir)
if err != nil {
return "", errors.Errorf("read config from both server and cache fail, err=%v", cacheErr)
if cacheErr != nil {
return "", errors.Errorf("read config from both server and cache fail, err=%vdataId=%s, group=%s, namespaceId=%s",
cacheErr, param.DataId, param.Group, clientConfig.NamespaceId)
}
logger.Warnf("read config from cache success, dataId=%s, group=%s, namespaceId=%s", param.DataId, param.Group, clientConfig.NamespaceId)
return cacheContent, nil
}
return response.Content, nil