Skip to content

Commit

Permalink
agolloMap缓存key改为endpoint+appid
Browse files Browse the repository at this point in the history
  • Loading branch information
ShineJstar authored Dec 11, 2020
1 parent 673e427 commit 5a7d06f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions viper-remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
_ viperConfigManager = apolloConfigManager{}
// getConfigManager方法每次返回新对象导致缓存无效,
// 这里通过endpoint作为key复一个对象
// key: endpoint value: agollo.Agollo
// key: endpoint+appid value: agollo.Agollo
agolloMap sync.Map
)

Expand Down Expand Up @@ -61,7 +61,8 @@ func newApolloConfigManager(appid, endpoint string, opts []agollo.Option) (*apol
return nil, errors.New("The appid is not set")
}

ag, err := newAgollo(appid, endpoint, opts)
ag, err :=
(appid, endpoint, opts)
if err != nil {
return nil, err
}
Expand All @@ -73,7 +74,7 @@ func newApolloConfigManager(appid, endpoint string, opts []agollo.Option) (*apol
}

func newAgollo(appid, endpoint string, opts []agollo.Option) (agollo.Agollo, error) {
i, found := agolloMap.Load(endpoint)
i, found := agolloMap.Load(endpoint + "/" + appid)
if !found {
ag, err := agollo.New(
endpoint,
Expand All @@ -87,7 +88,7 @@ func newAgollo(appid, endpoint string, opts []agollo.Option) (agollo.Agollo, err
// 监听并同步apollo配置
ag.Start()

agolloMap.Store(endpoint, ag)
agolloMap.Store(endpoint + "/" + appid, ag)

return ag, nil
}
Expand Down

0 comments on commit 5a7d06f

Please sign in to comment.