Skip to content

Commit 5a1da16

Browse files
committed
fixed README
1 parent 42e1f3f commit 5a1da16

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,21 @@ import (
4343
"time"
4444

4545
cache "github.com/Code-Hex/go-generics-cache"
46-
"github.com/Code-Hex/go-generics-cache/simple"
4746
)
4847

4948
func main() {
50-
// Create a simple cache. key as string, value as int.
51-
simpleCache := simple.NewCache[string, int]()
49+
// use simple cache algorithm without options.
50+
c := cache.New[string, int]()
51+
c.Set("a", 1)
52+
gota, aok := c.Get("a")
53+
gotb, bok := c.Get("b")
54+
fmt.Println(gota, aok) // 1 true
55+
fmt.Println(gotb, bok) // 0 false
5256

5357
// Create a cache for Number constraint. key as string, value as int.
54-
nc := cache.NewNumber[string, int](simpleCache)
58+
nc := cache.NewNumber[string, int]()
5559
nc.Set("age", 26, cache.WithExpiration(time.Hour))
5660

57-
// This will be compile error, because string is not satisfied cache.Number constraint.
58-
// nc := cache.NewNumber[string, string](simpleCache)
59-
6061
incremented := nc.Increment("age", 1)
6162
fmt.Println(incremented) // 27
6263

0 commit comments

Comments
 (0)