codeberg.org/gruf/go-cache/v3@v3.5.7/simple/pool.go (about)

     1  package simple
     2  
     3  import "sync"
     4  
     5  // entryPool is a global pool for Entry
     6  // objects, regardless of cache type.
     7  var entryPool sync.Pool
     8  
     9  // GetEntry fetches an Entry from pool, or allocates new.
    10  func GetEntry() *Entry {
    11  	v := entryPool.Get()
    12  	if v == nil {
    13  		return new(Entry)
    14  	}
    15  	return v.(*Entry)
    16  }
    17  
    18  // PutEntry replaces an Entry in the pool.
    19  func PutEntry(e *Entry) {
    20  	e.Key = nil
    21  	e.Value = nil
    22  	entryPool.Put(e)
    23  }