diff --git a/pkg/common/storage/cache/mcache/online.go b/pkg/common/storage/cache/mcache/online.go index 546ccef7a..f018da03e 100644 --- a/pkg/common/storage/cache/mcache/online.go +++ b/pkg/common/storage/cache/mcache/online.go @@ -7,10 +7,18 @@ import ( "github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache" ) +var ( + globalOnlineCache cache.OnlineCache + globalOnlineOnce sync.Once +) + func NewOnlineCache() cache.OnlineCache { - return &onlineCache{ - user: make(map[string]map[int32]struct{}), - } + globalOnlineOnce.Do(func() { + globalOnlineCache = &onlineCache{ + user: make(map[string]map[int32]struct{}), + } + }) + return globalOnlineCache } type onlineCache struct {