diff --git a/pkg/config/api.go b/pkg/config/api.go index aa88af3e..dcb9a794 100644 --- a/pkg/config/api.go +++ b/pkg/config/api.go @@ -79,6 +79,8 @@ type ConfigFileConfig interface { BaseConfig // IsEnable 是否启用配置中心 IsEnable() bool + // SetEnable 设置是否启用配置中心能力 + SetEnable(bool) // GetConfigConnectorConfig 配置文件连接器 GetConfigConnectorConfig() ConfigConnectorConfig // GetConfigFilterConfig 配置文件加密器 diff --git a/plugin/localregistry/common/cache_persist.go b/plugin/localregistry/common/cache_persist.go index 4246d3a7..069af4cd 100644 --- a/plugin/localregistry/common/cache_persist.go +++ b/plugin/localregistry/common/cache_persist.go @@ -47,6 +47,7 @@ const ( // CachePersistHandler 持久化工具类 type CachePersistHandler struct { + persistEnable bool persistDir string maxWriteRetry int maxReadRetry int @@ -61,9 +62,10 @@ type CacheFileInfo struct { } // NewCachePersistHandler create persistence handler -func NewCachePersistHandler(persistDir string, maxWriteRetry int, +func NewCachePersistHandler(persistEnable bool, persistDir string, maxWriteRetry int, maxReadRetry int, retryInterval time.Duration) (*CachePersistHandler, error) { handler := &CachePersistHandler{} + handler.persistEnable = persistEnable handler.persistDir = persistDir handler.maxReadRetry = maxReadRetry handler.maxWriteRetry = maxWriteRetry @@ -79,8 +81,8 @@ func (cph *CachePersistHandler) init() error { if nil == cph.marshaler { cph.marshaler = &jsonpb.Marshaler{} } - if err := model.EnsureAndVerifyDir(cph.persistDir); err != nil { - return err + if cph.persistEnable { + return model.EnsureAndVerifyDir(cph.persistDir) } return nil } diff --git a/plugin/localregistry/inmemory/inmemory.go b/plugin/localregistry/inmemory/inmemory.go index ede17ee8..13408141 100644 --- a/plugin/localregistry/inmemory/inmemory.go +++ b/plugin/localregistry/inmemory/inmemory.go @@ -166,12 +166,13 @@ func (g *LocalCache) Init(ctx *plugin.InitContext) error { g.eventToCacheHandlers[model.EventFaultDetect] = g.newFaultDetectCacheHandler() // 批量服务 g.eventToCacheHandlers[model.EventServices] = g.newServicesHandler() + g.cacheFromPersistAvailableInterval = ctx.Config.GetConsumer().GetLocalCache().GetPersistAvailableInterval() g.cachePersistHandler, err = lrplug.NewCachePersistHandler( + g.persistEnable, g.persistDir, ctx.Config.GetConsumer().GetLocalCache().GetPersistMaxWriteRetry(), ctx.Config.GetConsumer().GetLocalCache().GetPersistMaxReadRetry(), ctx.Config.GetConsumer().GetLocalCache().GetPersistRetryInterval()) - g.cacheFromPersistAvailableInterval = ctx.Config.GetConsumer().GetLocalCache().GetPersistAvailableInterval() if err != nil { return err }