-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
49 lines (37 loc) · 916 Bytes
/
example_test.go
File metadata and controls
49 lines (37 loc) · 916 Bytes
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
package bigcache_test
import (
"fmt"
"testing"
"time"
bigcache "github.com/ghorges/mybigcache"
)
func TestBigCacheSet(t *testing.T) {
cache := bigcache.NewBigCache(1024, 10*time.Minute, 2*time.Minute, removeCall, 100)
data := "hello"
cache.Set("123", []byte(data))
// test Del
// cache.Del("123")
data1, err := cache.Get("123")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("data is ", data1)
}
func TestBigCacheTimeout(t *testing.T) {
cache := bigcache.NewBigCache(1024, 1*time.Minute, 1*time.Minute, removeCall, 100)
data := "hello"
cache.Set("123", []byte(data))
cache.Set("231", []byte(data))
cache.Set("312", []byte(data))
ticker := time.NewTicker(1 * time.Minute)
for {
select {
case <-ticker.C:
cache.Set("keys", []byte("bigCache"))
}
}
}
func removeCall(wrappedEntry []byte, reason string) {
fmt.Println("oncall:", wrappedEntry, "reason is:", reason)
}