-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemoryProvider.go
More file actions
43 lines (36 loc) · 885 Bytes
/
Copy pathMemoryProvider.go
File metadata and controls
43 lines (36 loc) · 885 Bytes
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
package go2cache
import (
"sync"
)
var mmp = &MemoryProvider{memoryCacheRegion: make(map[string]*MemoryCache)}
//基于redis缓存提供者
type MemoryProvider struct {
//同步 MemoryCache map
mu sync.RWMutex
//基于map的region 和cache的封装
memoryCacheRegion map[string]*MemoryCache
//regins
regions []Region
}
//构建region cache
func (p *MemoryProvider) BuildCache(region string) (interface{}, error) {
p.mu.Lock()
defer p.mu.Unlock()
cache := mmp.memoryCacheRegion[region]
if cache == nil {
cache = BuildMemoryCache()
mmp.memoryCacheRegion[region] = cache
p.regions = append(p.regions, Region{Name: region})
}
return cache, nil
}
//获取region 列表
func (p *MemoryProvider) GetRegions() []Region {
return p.regions
}
func (p *MemoryProvider) Name() string {
return "memory_provider"
}
func (p *MemoryProvider) Level() int {
return LEVEL_1
}