blob: a61f296214340422bed677d63b600165a231941c (
plain)
| 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
 | package memstore
import (
	"sync"
)
type cache struct {
	data  map[string]valueType
	mutex sync.RWMutex
}
func newCache() *cache {
	return &cache{
		data: make(map[string]valueType),
	}
}
func (c *cache) value(name string) (valueType, bool) {
	c.mutex.RLock()
	defer c.mutex.RUnlock()
	v, ok := c.data[name]
	return v, ok
}
func (c *cache) setValue(name string, value valueType) {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	c.data[name] = value
}
func (c *cache) delete(name string) {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	if _, ok := c.data[name]; ok {
		delete(c.data, name)
	}
}
 |