Repository navigation
Expand file tree
/
Copy pathcache_test.go
More file actions
123 lines (86 loc) · 1.85 KB
/
Copy pathcache_test.go
File metadata and controls
123 lines (86 loc) · 1.85 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package cache
import (
"testing"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/dulumao/cache/drivers"
"github.com/dulumao/cache/options"
)
func TestCreate(t *testing.T) {
var err error
//c, _ := Use(drivers.DriverBoltdb, &options.Options{
// Bboltdb: &options.Bboltdb{
// Path: "cache.db",
// Mode: 0666,
// },
//})
c, err := Use(drivers.DriverCache2go, &options.Options{
Name: "cache",
})
err = c.Set("k1", "v1", 1*time.Second)
c.Set("k2", "v2", 1*time.Second)
c.Set("k3", "v3", 1*time.Second)
if err != nil {
panic(err)
}
//time.Sleep(2*time.Second)
err = c.Clear()
//if err != nil {
// panic(err)
//}
spew.Dump(c.Exists("k1"))
spew.Dump(c.MustGet("k2"))
}
func TestGetAndSet(t *testing.T) {
var err error
c, err := Use(drivers.DriverCache2go, &options.Options{
Name: "cache",
})
spew.Dump(c)
var k4 interface{}
k4, err = c.GetAndSet("k4", func() (interface{}, error) {
return "k4 value", nil
}, 1*time.Second)
if err != nil {
panic(err)
}
spew.Dump(k4)
//time.Sleep(2 * time.Second)
spew.Dump(c.Exists("k4"))
}
func TestLru(t *testing.T) {
c, err := Use(drivers.DriverLru, &options.Options{
Lru: &options.Lru{Size: 10},
})
err = c.Set("k1", "v1", 1*time.Second)
c.Set("k2", "v2", 1*time.Second)
c.Set("k3", "v3", 1*time.Second)
if err != nil {
panic(err)
}
//time.Sleep(2*time.Second)
//err = c.Clear()
//if err != nil {
// panic(err)
//}
spew.Dump(c.Exists("k1"))
spew.Dump(c.MustGet("k2"))
}
func TestDelete(t *testing.T) {
var err error
c, err := Use(drivers.DriverCache2go, &options.Options{
Name: "cache",
})
if err != nil {
panic(err)
}
var k4 interface{}
_ = k4
//c.Set("k4", "asdad", 10*time.Second)
k4, err = c.GetAndSet("k4", func() (interface{}, error) {
return "k4 value", nil
}, 10*time.Second)
c.Delete("k4")
d, _ := c.Get("k4")
spew.Dump(d)
}