mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
35 lines
476 B
Go
35 lines
476 B
Go
|
package datanode
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
type Cache struct {
|
||
|
cacheMu sync.RWMutex
|
||
|
cacheMap map[UniqueID]bool
|
||
|
}
|
||
|
|
||
|
func newCache() *Cache {
|
||
|
return &Cache{
|
||
|
cacheMap: make(map[UniqueID]bool),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (c *Cache) checkIfCached(key UniqueID) bool {
|
||
|
c.cacheMu.Lock()
|
||
|
defer c.cacheMu.Unlock()
|
||
|
|
||
|
if _, ok := c.cacheMap[key]; !ok {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func (c *Cache) Cache(segID UniqueID) {
|
||
|
c.cacheMu.Lock()
|
||
|
defer c.cacheMu.Unlock()
|
||
|
|
||
|
c.cacheMap[segID] = true
|
||
|
}
|