mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
9d81a90402
Resolves: #6858 Signed-off-by: yangxuan <xuan.yang@zilliz.com>
41 lines
595 B
Go
41 lines
595 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()
|
|
|
|
_, ok := c.cacheMap[key]
|
|
return ok
|
|
}
|
|
|
|
func (c *Cache) Cache(segID UniqueID) {
|
|
c.cacheMu.Lock()
|
|
defer c.cacheMu.Unlock()
|
|
|
|
c.cacheMap[segID] = true
|
|
}
|
|
|
|
func (c *Cache) Remove(segIDs ...UniqueID) {
|
|
c.cacheMu.Lock()
|
|
defer c.cacheMu.Unlock()
|
|
|
|
for _, id := range segIDs {
|
|
delete(c.cacheMap, id)
|
|
}
|
|
}
|