gitee.com/quant1x/gox@v1.21.2/cache/map.go (about)

     1  package cache
     2  
     3  import "sync"
     4  
     5  // Map 二次封装的泛型sync.Map
     6  type Map[K any, V any] struct {
     7  	syncMap sync.Map
     8  }
     9  
    10  func (this *Map[K, V]) Get(k K) (V, bool) {
    11  	obj, ok := this.syncMap.Load(k)
    12  	var v V
    13  	if ok {
    14  		v, ok = obj.(V)
    15  	}
    16  	return v, ok
    17  }
    18  
    19  func (this *Map[K, V]) Put(k K, v V) {
    20  	this.syncMap.Store(k, v)
    21  }