-
Notifications
You must be signed in to change notification settings - Fork 24
/
control_point_cache.go
45 lines (38 loc) · 1.1 KB
/
control_point_cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package controlpointcache
import (
"sync"
)
// Provide provides control point cache.
func Provide() *ControlPointCache {
return NewControlPointCache()
}
// NewControlPointCache returns new instance of control point cache.
func NewControlPointCache() *ControlPointCache {
return &ControlPointCache{
controlPoints: map[ControlPoint]struct{}{},
}
}
// ControlPointCache keeps information about control points their services.
type ControlPointCache struct {
sync.Mutex
controlPoints map[ControlPoint]struct{}
}
// Put inserts control point with given name and service.
func (c *ControlPointCache) Put(name, service string) {
c.Lock()
defer c.Unlock()
c.controlPoints[ControlPoint{Name: name, Service: service}] = struct{}{}
}
// GetAllAndClear returns the current state of cache and clears the cache.
func (c *ControlPointCache) GetAllAndClear() map[ControlPoint]struct{} {
c.Lock()
defer c.Unlock()
result := c.controlPoints
c.controlPoints = map[ControlPoint]struct{}{}
return result
}
// ControlPoint represents control point kept in the cache.
type ControlPoint struct {
Name string
Service string
}