Skip to content

Commit 8b9e75f

Browse files
committed
fixed README
1 parent 25c842d commit 8b9e75f

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,60 @@ go version devel go1.18-c2397905e0 Sat Nov 13 03:33:55 2021 +0000 darwin/arm64
2020

2121
## Install
2222

23-
go get github.com/Code-Hex/go-generics-cache
23+
$ go get github.com/Code-Hex/go-generics-cache
2424

2525
## Usage
2626

2727
See also [examples](https://github.com/Code-Hex/go-generics-cache/blob/main/example_test.go)
2828

29+
playground: https://gotipplay.golang.org/p/FXRk6ngYV-s
30+
2931
```go
3032
package main
3133

3234
import (
3335
"fmt"
36+
"time"
3437

3538
cache "github.com/Code-Hex/go-generics-cache"
3639
)
3740

3841
func main() {
39-
// Create a cache. key as string, value as int.
40-
c1 := cache.New[string, int]()
42+
// Create a cache. key as string, value as int.
43+
c1 := cache.New[string, int]()
4144

42-
// Sets the value of int. you can set with expiration option.
43-
c1.Set("foo", 1, cache.WithExpiration(time.Hour))
45+
// Sets the value of int. you can set with expiration option.
46+
c1.Set("foo", 1, cache.WithExpiration(time.Hour))
4447

45-
// the value never expires.
46-
c1.Set("bar", 2)
48+
// the value never expires.
49+
c1.Set("bar", 2)
4750

48-
foo, ok := c.Get("foo")
51+
foo, ok := c1.Get("foo")
4952
if ok {
5053
fmt.Println(foo) // 1
5154
}
5255

53-
fmt.Println(c.Keys()) // outputs "foo" "bar" may random
56+
fmt.Println(c1.Keys()) // outputs "foo" "bar" may random
5457

55-
// Create a cache. key as int, value as string.
56-
c2 := cache.New[int, string]()
57-
c2.Set(1, "baz")
58-
baz, ok := c.Get(1)
58+
// Create a cache. key as int, value as string.
59+
c2 := cache.New[int, string]()
60+
c2.Set(1, "baz")
61+
baz, ok := c2.Get(1)
5962
if ok {
6063
fmt.Println(baz) // "baz"
6164
}
6265

6366
// Create a cache for Number constraint.. key as string, value as int.
6467
nc := cache.NewNumber[string, int]()
65-
nc.Set("age", 26)
68+
nc.Set("age", 26)
6669

67-
// This will be compile error, because string is not satisfied cache.Number constraint.
68-
// nc := cache.NewNumber[string, string]()
70+
// This will be compile error, because string is not satisfied cache.Number constraint.
71+
// nc := cache.NewNumber[string, string]()
6972

70-
incremented, _ := nc.Increment("age", 1)
71-
fmt.Println(incremented) // 27
73+
incremented, _ := nc.Increment("age", 1)
74+
fmt.Println(incremented) // 27
7275

73-
decremented, _ := nc.Decrement("age", 1)
74-
fmt.Println(decremented) // 26
76+
decremented, _ := nc.Decrement("age", 1)
77+
fmt.Println(decremented) // 26
7578
}
7679
```

0 commit comments

Comments
 (0)