mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 09:38:39 +08:00
- remove the unused LRU cache - add new LRU cache impl which wraps github.com/karlseguin/ccache related #30361 --------- Signed-off-by: yah01 <yang.cen@zilliz.com>
39 lines
658 B
Go
39 lines
658 B
Go
package cache
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type CacheSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *CacheSuite) TestLRUCache() {
|
|
size := 10
|
|
cache := NewLRUCache[int, int](int32(size), func(key int) (int, bool) {
|
|
return key, true
|
|
}, nil)
|
|
|
|
for i := 1; i <= size; i++ {
|
|
item, ok := cache.GetAndPin(i)
|
|
s.True(ok)
|
|
s.Equal(i, item.Value())
|
|
item.Unpin()
|
|
}
|
|
|
|
s.False(cache.Contain(size + 1))
|
|
for i := 1; i <= size; i++ {
|
|
item, ok := cache.GetAndPin(size + i)
|
|
s.True(ok)
|
|
s.Equal(size+i, item.Value())
|
|
s.False(cache.Contain(i))
|
|
item.Unpin()
|
|
}
|
|
}
|
|
|
|
func TestCacheSuite(t *testing.T) {
|
|
suite.Run(t, new(CacheSuite))
|
|
}
|