forked from Angey40/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cachemap.go
43 lines (36 loc) · 854 Bytes
/
cachemap.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
package cachemap
import (
"github.com/Denis-Oakley/BaiduPCS-Go/baidupcs/expires"
"sync"
)
var (
GlobalCacheOpMap = CacheOpMap{}
)
type (
CacheOpMap struct {
cachePool sync.Map
}
)
func (cm *CacheOpMap) LazyInitCachePoolOp(op string) CacheUnit {
cacheItf, _ := cm.cachePool.LoadOrStore(op, &cacheUnit{})
return cacheItf.(CacheUnit)
}
func (cm *CacheOpMap) RemoveCachePoolOp(op string) {
cm.cachePool.Delete(op)
}
// ClearInvalidate 清除已过期的数据(一般用不到)
func (cm *CacheOpMap) ClearInvalidate() {
cm.cachePool.Range(func(_, cacheItf interface{}) bool {
cache := cacheItf.(CacheUnit)
cache.Range(func(key interface{}, exp expires.DataExpires) bool {
if exp.IsExpires() {
cache.Delete(key)
}
return true
})
return true
})
}
// PrintAll 输出所有缓冲项目
func (cm *CacheOpMap) PrintAll() {
}