Skip to content

Commit

Permalink
feat: 禁用缓存持久化时不自动创建目录;提供禁用配置中心的API (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
WTIFS authored Jul 19, 2024
1 parent 9a5812f commit 4ac5155
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type ConfigFileConfig interface {
BaseConfig
// IsEnable 是否启用配置中心
IsEnable() bool
// SetEnable 设置是否启用配置中心能力
SetEnable(bool)
// GetConfigConnectorConfig 配置文件连接器
GetConfigConnectorConfig() ConfigConnectorConfig
// GetConfigFilterConfig 配置文件加密器
Expand Down
8 changes: 5 additions & 3 deletions plugin/localregistry/common/cache_persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (

// CachePersistHandler 持久化工具类
type CachePersistHandler struct {
persistEnable bool
persistDir string
maxWriteRetry int
maxReadRetry int
Expand All @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/localregistry/inmemory/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 4ac5155

Please sign in to comment.