From 4ac5155cfa0c91d8c039e3d5cbf977a21492a56e Mon Sep 17 00:00:00 2001 From: WTIFS <9314475+WTIFS@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:18:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A6=81=E7=94=A8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=8C=81=E4=B9=85=E5=8C=96=E6=97=B6=E4=B8=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=9B=AE=E5=BD=95=EF=BC=9B=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=BF=83=E7=9A=84?= =?UTF-8?q?API=20(#198)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/config/api.go | 2 ++ plugin/localregistry/common/cache_persist.go | 8 +++++--- plugin/localregistry/inmemory/inmemory.go | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) 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 }