milvus/internal/proxy/id_cache.go
shaoyue 5b50731ff4
Fix searchResultBufFlags & queryResultBufFlags memory leak (#11585)
Signed-off-by: shaoyue.chen <shaoyue.chen@zilliz.com>
2021-11-16 14:13:12 +08:00

32 lines
597 B
Go

package proxy
import (
"strconv"
"time"
"github.com/patrickmn/go-cache"
)
type idCache struct {
cache *cache.Cache
}
func newIDCache(defaultExpiration, cleanupInterval time.Duration) *idCache {
c := cache.New(defaultExpiration, cleanupInterval)
return &idCache{
cache: c,
}
}
func (r *idCache) Set(id UniqueID, value bool) {
r.cache.Set(strconv.FormatInt(id, 36), value, 0)
}
func (r *idCache) Get(id UniqueID) (value bool, exists bool) {
valueRaw, exists := r.cache.Get(strconv.FormatInt(id, 36))
if valueRaw == nil {
return false, exists
}
return valueRaw.(bool), exists
}