-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcache.go
37 lines (34 loc) · 907 Bytes
/
gcache.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
package main
import (
"gitee.com/johng/gf/g/os/gcache"
"time"
"fmt"
"strconv"
)
func main() {
for i := 0; i < 10; i++ {
gcache.Set(strconv.Itoa(i), strconv.Itoa(i), 0)
}
fmt.Println(gcache.Size())
fmt.Println(gcache.Keys())
gcache.SetCap(2)
time.Sleep(3*time.Second)
fmt.Println(gcache.Size())
fmt.Println(gcache.Keys())
return
gcache.Set("k1", "v1", 1000)
gcache.Set("k2", "v2", 2000)
fmt.Println(gcache.Keys())
fmt.Println(gcache.Values())
fmt.Println(gcache.Size())
time.Sleep(500*time.Millisecond)
fmt.Println(gcache.Get("k1"))
fmt.Println(gcache.Get("k2"))
time.Sleep(400*time.Millisecond)
fmt.Println(gcache.Get("k1"))
fmt.Println(gcache.Get("k2"))
time.Sleep(3000*time.Millisecond)
fmt.Println(gcache.Get("k1"))
fmt.Println(gcache.Get("k2"))
time.Sleep(3000*time.Millisecond)
}