-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (36 loc) · 1.1 KB
/
main.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
package main
import (
"fmt"
"lru/cache"
"math/rand"
"strconv"
"sync"
"time"
)
var (
wg sync.WaitGroup
lruCache *cache.Cache
)
func init() {
lruCache = cache.NewCache(1000)
}
func main() {
for i := 1; i < 1001; i++ {
wg.Add(1)
go lruCacheTest(i)
}
wg.Wait()
fmt.Println(len(lruCache.Cache), "prev", lruCache.Cache[strconv.Itoa(10)].Prev, "next", lruCache.Cache[strconv.Itoa(10)].Next, "head", lruCache.Head, "tail", lruCache.Tail)
lruCache.Get(strconv.Itoa(10))
fmt.Println(len(lruCache.Cache), "prev", lruCache.Cache[strconv.Itoa(10)].Prev, "next", lruCache.Cache[strconv.Itoa(10)].Next, "head", lruCache.Head, "tail", lruCache.Tail)
lruCache.Set(strconv.Itoa(1200), make(chan string, 10), 0)
fmt.Println(len(lruCache.Cache), "prev", lruCache.Cache[strconv.Itoa(1200)].Prev, "next", lruCache.Cache[strconv.Itoa(1200)].Next, "head", lruCache.Head, "tail", lruCache.Tail)
}
func lruCacheTest(i int) {
rand.Seed(time.Now().Unix())
lruCache.Set(strconv.Itoa(i), i, 0)
lruCache.Get(strconv.Itoa(i))
time.Sleep(1 * 1000 * time.Millisecond)
lruCache.Get(strconv.Itoa(i))
wg.Done()
}