-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (46 loc) · 969 Bytes
/
Copy pathmain.go
File metadata and controls
59 lines (46 loc) · 969 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
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/thiagozs/go-cache"
"github.com/thiagozs/go-cache/kind"
)
func main() {
opts := []cache.Options{
cache.OptFolder("./tmp/cache"),
cache.OptFile("cache.db"),
cache.OptTTL(3000),
cache.OptLogDebug(false),
cache.OptLogDisable(false),
cache.OptDriver(kind.BUNTDB),
}
cache, err := cache.New(opts...)
if err != nil {
fmt.Println("Error:", err)
return
}
cache.WriteKeyVal("key1", "value1")
cache.WriteKeyVal("key2", "value2")
v1, err := cache.GetVal("key1")
if err != nil {
fmt.Println("Error:", err)
return
}
v2, err := cache.GetVal("key2")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("v1:", v1)
fmt.Println("v2:", v2)
cache.WriteKeyVal("key5", "1")
v5, err := cache.Incr("key5")
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println("v5:", v5)
v6, err := cache.Decr("key5")
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println("v6:", v6)
}