Skip to content

Commit

Permalink
update cache file name base on appid and cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
philchia committed Nov 5, 2018
1 parent 9c8aae8 commit 3323776
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions agollo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestAgolloStart(t *testing.T) {
t.Errorf("Start with app.properties should return nil, got :%v", err)
}
defer Stop()
defer os.Remove(defaultDumpFile)
defer os.Remove(defaultClient.getDumpFileName())

if err := defaultClient.loadLocal(defaultDumpFile); err != nil {
if err := defaultClient.loadLocal(defaultClient.getDumpFileName()); err != nil {
t.Errorf("loadLocal should return nil, got: %v", err)
}

Expand Down
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agollo
import (
"context"
"encoding/json"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -83,7 +84,7 @@ func (c *Client) Stop() error {
// fetchAllCinfig fetch from remote, if failed load from local file
func (c *Client) preload() error {
if err := c.longPoller.preload(); err != nil {
return c.loadLocal(defaultDumpFile)
return c.loadLocal(c.getDumpFileName())
}
return nil
}
Expand Down Expand Up @@ -188,7 +189,7 @@ func (c *Client) handleResult(result *result) *ChangeEvent {
c.setReleaseKey(result.NamespaceName, result.ReleaseKey)

// dump caches to file
c.dump(defaultDumpFile)
c.dump(c.getDumpFileName())

if len(ret.Changes) == 0 {
return nil
Expand All @@ -197,6 +198,10 @@ func (c *Client) handleResult(result *result) *ChangeEvent {
return &ret
}

func (c *Client) getDumpFileName() string {
return fmt.Sprintf(".%s_%s", c.conf.AppID, c.conf.Cluster)
}

func (c *Client) getReleaseKey(namespace string) string {
releaseKey, _ := c.releaseKeyRepo.get(namespace)
return releaseKey
Expand Down

0 comments on commit 3323776

Please sign in to comment.