@@ -62,12 +62,12 @@ type testValue struct {
6262
6363func (v testValue ) Timestamp () int64 { return v .TS }
6464
65- func TestUnit_AutoClean (t * testing.T ) {
65+ func TestUnit_OptTimeClean (t * testing.T ) {
6666 ctx , cancel := context .WithCancel (context .Background ())
6767 defer cancel ()
6868
6969 c := cache.New [string , testValue ](
70- cache .AutoClean [string , testValue ](ctx , time .Millisecond * 100 ),
70+ cache .OptTimeClean [string , testValue ](ctx , time .Millisecond * 100 ),
7171 )
7272
7373 c .Set ("foo" , testValue {Val : "bar" , TS : time .Now ().Add (time .Millisecond * 200 ).Unix ()})
@@ -78,12 +78,30 @@ func TestUnit_AutoClean(t *testing.T) {
7878 casecheck .False (t , c .Has ("foo" ))
7979}
8080
81+ func TestUnit_OptCountRandomClean (t * testing.T ) {
82+ ctx , cancel := context .WithCancel (context .Background ())
83+ defer cancel ()
84+
85+ c := cache.New [int , int ](
86+ cache .OptCountRandomClean [int , int ](ctx , 100 , time .Second ),
87+ )
88+
89+ for i := 0 ; i < 200 ; i ++ {
90+ c .Set (i , i )
91+ }
92+ casecheck .Equal (t , 200 , c .Size ())
93+
94+ time .Sleep (time .Second * 2 )
95+
96+ casecheck .Equal (t , 100 , c .Size ())
97+ }
98+
8199func Benchmark_New (b * testing.B ) {
82100 ctx , cancel := context .WithCancel (context .Background ())
83101 defer cancel ()
84102
85103 c := cache.New [string , testValue ](
86- cache .AutoClean [string , testValue ](ctx , time .Millisecond * 100 ),
104+ cache .OptTimeClean [string , testValue ](ctx , time .Millisecond * 100 ),
87105 )
88106
89107 b .ReportAllocs ()
0 commit comments