@@ -43,20 +43,21 @@ import (
43
43
" time"
44
44
45
45
cache " github.com/Code-Hex/go-generics-cache"
46
- " github.com/Code-Hex/go-generics-cache/simple"
47
46
)
48
47
49
48
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
52
56
53
57
// 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 ]()
55
59
nc.Set (" age" , 26 , cache.WithExpiration (time.Hour ))
56
60
57
- // This will be compile error, because string is not satisfied cache.Number constraint.
58
- // nc := cache.NewNumber[string, string](simpleCache)
59
-
60
61
incremented := nc.Increment (" age" , 1 )
61
62
fmt.Println (incremented) // 27
62
63
0 commit comments