summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-cache/v3/simple/pool.go
blob: 34ae175468298e6ea72f5c3cfdddd7720c67c660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package simple

import "sync"

// entryPool is a global pool for Entry
// objects, regardless of cache type.
var entryPool sync.Pool

// GetEntry fetches an Entry from pool, or allocates new.
func GetEntry() *Entry {
	v := entryPool.Get()
	if v == nil {
		return new(Entry)
	}
	return v.(*Entry)
}

// PutEntry replaces an Entry in the pool.
func PutEntry(e *Entry) {
	e.Key = nil
	e.Value = nil
	entryPool.Put(e)
}