Skip to content

Commit

Permalink
Merge ab24814 into 7266e61
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Aug 5, 2019
2 parents 7266e61 + ab24814 commit 3d59441
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ Installation
``` shell
gopm get github.com/cihub/seelog -v -g
gopm get github.com/coocood/freecache -v -g
gopm get github.com/zouyx/agollo -v -g
```

或者

``` shell
go get -u github.com/cihub/seelog
go get -u github.com/coocood/freecache
go get -u github.com/zouyx/agollo
```


Expand Down Expand Up @@ -71,6 +69,14 @@ func main() {
}
```

- 启动agollo - 自定义cache控件 (v1.7.0+)

``` go
func main() {
go agollo.StartWithCache(cacheInterface)
}
```

- 监听变更事件(阻塞)

``` go
Expand Down
3 changes: 2 additions & 1 deletion depend.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gopm get github.com/cihub/seelog -v -g
go get -u github.com/cihub/seelog
go get -u github.com/coocood/freecache
24 changes: 22 additions & 2 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,29 @@ var (
currentConnApolloConfig = &currentApolloConfig{}

//config from apollo
apolloConfigCache = freecache.NewCache(apolloConfigCacheSize)
apolloConfigCache CacheInterface = freecache.NewCache(apolloConfigCacheSize)
)

func initCache(cacheInterface CacheInterface) {
apolloConfigCache=cacheInterface
}

type CacheInterface interface {
Set(key, value []byte, expireSeconds int) (err error)

EntryCount() (entryCount int64)

Get(key []byte) (value []byte, err error)

Del(key []byte) (affected bool)

NewIterator() *freecache.Iterator

TTL(key []byte) (timeLeft uint32, err error)

Clear()
}

type currentApolloConfig struct {
l sync.RWMutex
config *ApolloConnConfig
Expand Down Expand Up @@ -128,7 +148,7 @@ func updateApolloConfigCacheTime(expireTime int) {
}
}

func GetApolloConfigCache() *freecache.Cache {
func GetApolloConfigCache() CacheInterface {
return apolloConfigCache
}

Expand Down
11 changes: 11 additions & 0 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ func Start() error {
}

func StartWithLogger(loggerInterface LoggerInterface) error {
return StartWithParams(loggerInterface,nil)
}

func StartWithCache(cacheInterface CacheInterface) error {
return StartWithParams(nil,cacheInterface)
}

func StartWithParams(loggerInterface LoggerInterface,cacheInterface CacheInterface) error {
if loggerInterface != nil {
initLogger(loggerInterface)
}
if cacheInterface != nil {
initCache(cacheInterface)
}

//init server ip list
go initServerIpList()
Expand Down

0 comments on commit 3d59441

Please sign in to comment.