-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache_test.go
62 lines (50 loc) · 1.24 KB
/
cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gocache
import (
"fmt"
"testing"
"time"
)
func TestNew(t *testing.T) {
c := New()
defer c.ShutDown()
expireTime := 10 * time.Second
key := "a"
value := []byte("value")
c.Set(key, value, expireTime)
v, expireMillDateTime, exist := c.Get(key)
if exist {
fmt.Println(key, "is", string(v), expireMillDateTime, exist)
} else {
fmt.Println(key, " not exist")
}
for i := 0; i < 5; i++ {
c.Set(fmt.Sprintf("%s-%d", key, i), []byte(fmt.Sprintf("hi:%d", i)), 5*time.Second)
}
oldK, oldExpireMillDateTime, oldExist := c.GetOldestKey()
fmt.Println("oldest:", oldK, oldExpireMillDateTime, oldExist)
for _, k := range c.KeyList() {
v, expireMillDateTime, exist = c.Get(k)
if exist {
fmt.Println(k, "is", string(v), expireMillDateTime, exist)
} else {
fmt.Println(k, "not exist")
}
}
time.Sleep(10 * time.Second)
v, expireMillDateTime, exist = c.Get(key)
if exist {
fmt.Println(key, "is", string(v), expireMillDateTime, exist)
} else {
fmt.Println(key, "not exist")
}
}
func TestNew2(t *testing.T) {
c := New()
defer c.ShutDown()
for i := 0; i < 5; i++ {
c.Set(fmt.Sprintf("%s-%d", "xx", i), []byte(fmt.Sprintf("hi:%d", i)), 5*time.Second)
}
for i := 0; i < c.Size(); i++ {
fmt.Println(c.Index(i))
}
}