milvus/pkg/util/cache/cache_test.go
yah01 57397b1307
enhance: add new LRU cache impl (#30360)
- 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>
2024-02-27 20:58:40 +08:00

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))
}