2023-12-28 03:17:41 +00:00
|
|
|
package groupcache
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
2023-12-28 04:11:21 +00:00
|
|
|
// workspace holds the "global" state for groupcache.
|
2023-12-28 03:17:41 +00:00
|
|
|
type workspace struct {
|
|
|
|
httpPoolMade bool
|
|
|
|
portPicker func(groupName string) PeerPicker
|
|
|
|
|
|
|
|
mu sync.RWMutex
|
|
|
|
groups map[string]*Group
|
|
|
|
|
|
|
|
initPeerServerOnce sync.Once
|
|
|
|
initPeerServer func()
|
|
|
|
|
|
|
|
// newGroupHook, if non-nil, is called right after a new group is created.
|
|
|
|
newGroupHook func(*Group)
|
|
|
|
}
|
|
|
|
|
2023-12-28 04:11:21 +00:00
|
|
|
// DefaultWorkspace is the default workspace used by non-workspace-aware APIs.
|
|
|
|
// If your application does not need to recreate groupcache resources,
|
|
|
|
// you should use the non-workspace-aware APIs.
|
|
|
|
// This is likely the most common case.
|
2023-12-28 03:17:41 +00:00
|
|
|
var DefaultWorkspace = NewWorkspace()
|
|
|
|
|
2023-12-28 04:11:21 +00:00
|
|
|
// NewWorkspace creates an explicit workspace for workspace-aware APIs.
|
|
|
|
// If your application needs to recreate groupcache resources at some
|
|
|
|
// point, you should use the workspace-aware APIs.
|
|
|
|
// In order to release current groupcache resources, your application
|
|
|
|
// would drop all references to the workspace.
|
2023-12-28 03:17:41 +00:00
|
|
|
func NewWorkspace() *workspace {
|
|
|
|
return &workspace{
|
|
|
|
groups: make(map[string]*Group),
|
|
|
|
}
|
|
|
|
}
|