Skip to content

Commit 4e9b01a

Browse files
committed
fixed example test
1 parent 6e63277 commit 4e9b01a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

example_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@ package cache_test
22

33
import (
44
"fmt"
5+
"time"
56

67
cache "github.com/Code-Hex/go-generics-cache"
78
"github.com/Code-Hex/go-generics-cache/simple"
89
)
910

1011
func ExampleNumberCache() {
11-
c := cache.NewNumber[string, int](simple.NewCache[string, int]())
12-
c.Set("a", 1)
13-
c.Set("b", 2)
14-
av := c.Increment("a", 1)
15-
gota, aok := c.Get("a")
12+
c := simple.NewCache[string, int]()
13+
nc := cache.NewNumber[string, int](c)
14+
nc.Set("a", 1)
15+
nc.Set("b", 2, cache.WithExpiration(time.Minute))
16+
av := nc.Increment("a", 1)
17+
gota, aok := nc.Get("a")
1618

17-
bv := c.Decrement("b", 1)
18-
gotb, bok := c.Get("b")
19+
bv := nc.Decrement("b", 1)
20+
gotb, bok := nc.Get("b")
1921

2022
// not set keys
21-
cv := c.Increment("c", 100)
22-
dv := c.Decrement("d", 100)
23+
cv := nc.Increment("c", 100)
24+
dv := nc.Decrement("d", 100)
2325
fmt.Println(av, gota, aok)
2426
fmt.Println(bv, gotb, bok)
2527
fmt.Println(cv)

0 commit comments

Comments
 (0)