Skip to content

Commit

Permalink
:squirrel: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
orca-zhang committed Dec 24, 2021
1 parent 5085847 commit 33f8b8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dist/dist.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const topic = "orca-zhang/orcache"

// `RedisCli`` interface used by `dist` component
type RedisCli interface {
// if the redis client is ready
OK() bool
Expand All @@ -32,6 +33,7 @@ func delAll(pool, key string) {
}
}

// Init `dist` component with redis client
func Init(r RedisCli) {
if redisCli != r {
redisCli = r
Expand Down Expand Up @@ -59,8 +61,8 @@ func Init(r RedisCli) {
}

// Bind - to enable distributed consistency
// `pool` is not necessary, it can be used to classify instances that store same items
// but it will be more efficient if it is not empty
// `pool` is not necessary, it can be used to classify instances that store same items, but it will be more efficient if it is not empty
// `caches` is cache instances to be binded
func Bind(pool string, caches ...*orcache.Cache) error {
c, _ := m.LoadOrStore(pool, &[]*orcache.Cache{})
*(c.(*[]*orcache.Cache)) = append(*(c.(*[]*orcache.Cache)), caches...)
Expand Down
3 changes: 3 additions & 0 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type StatsNode struct {

// Bind - to stats a cache
// `pool` can be used to classify instances that store same items
// `caches` is cache instances to be binded
func Bind(pool string, caches ...*orcache.Cache) error {
v, _ := m.LoadOrStore(pool, &StatsNode{})
for _, c := range caches {
Expand All @@ -33,10 +34,12 @@ func Bind(pool string, caches ...*orcache.Cache) error {
// `k` is categoy, type is string
// `v` is node, type is `*stats.StatsNode`
//
// ``` go
// stats.Stats().Range(func(k, v interface{}) bool {
// fmt.Println("stats:", k, v)
// return true
// })
// ```
func Stats() *sync.Map {
return &m
}

0 comments on commit 33f8b8c

Please sign in to comment.