github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/baidupcs/expires/cachemap/cachemap.go (about) 1 package cachemap 2 3 import ( 4 "github.com/qjfoidnh/BaiduPCS-Go/baidupcs/expires" 5 "sync" 6 ) 7 8 var ( 9 GlobalCacheOpMap = CacheOpMap{} 10 ) 11 12 type ( 13 CacheOpMap struct { 14 cachePool sync.Map 15 } 16 ) 17 18 func (cm *CacheOpMap) LazyInitCachePoolOp(op string) CacheUnit { 19 cacheItf, _ := cm.cachePool.LoadOrStore(op, &cacheUnit{}) 20 return cacheItf.(CacheUnit) 21 } 22 23 func (cm *CacheOpMap) RemoveCachePoolOp(op string) { 24 cm.cachePool.Delete(op) 25 } 26 27 // ClearInvalidate 清除已过期的数据(一般用不到) 28 func (cm *CacheOpMap) ClearInvalidate() { 29 cm.cachePool.Range(func(_, cacheItf interface{}) bool { 30 cache := cacheItf.(CacheUnit) 31 cache.Range(func(key interface{}, exp expires.DataExpires) bool { 32 if exp.IsExpires() { 33 cache.Delete(key) 34 } 35 return true 36 }) 37 return true 38 }) 39 } 40 41 // PrintAll 输出所有缓冲项目 42 func (cm *CacheOpMap) PrintAll() { 43 }