Skip to content

Commit 8cbc483

Browse files
committed
fixed README for simple cache
1 parent 5c0a125 commit 8cbc483

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

README.md

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
go-generics-cache is an in-memory key:value store/cache that is suitable for applications running on a single machine. This in-memory cache uses [Go Generics](https://go.dev/blog/generics-proposal) which will be introduced in 1.18.
66

7+
- a thread-safe
78
- implemented with [Go Generics](https://go.dev/blog/generics-proposal)
8-
- a thread-safe `map[string]interface{}` with expiration times
9+
- Simple `map[string]interface{}` with expiration times
10+
- See [examples](https://github.com/Code-Hex/go-generics-cache/blob/main/simple/example_test.go)
911
- LRU cache
1012
- See [examples](https://github.com/Code-Hex/go-generics-cache/blob/main/lru/example_test.go)
1113

@@ -30,8 +32,6 @@ go version devel go1.18-c2397905e0 Sat Nov 13 03:33:55 2021 +0000 darwin/arm64
3032

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

33-
playground: https://gotipplay.golang.org/p/FXRk6ngYV-s
34-
3535
```go
3636
package main
3737

@@ -40,44 +40,24 @@ import (
4040
"time"
4141

4242
cache "github.com/Code-Hex/go-generics-cache"
43+
"github.com/Code-Hex/go-generics-cache/simple"
4344
)
4445

4546
func main() {
46-
// Create a cache. key as string, value as int.
47-
c1 := cache.New[string, int]()
48-
49-
// Sets the value of int. you can set with expiration option.
50-
c1.Set("foo", 1, cache.WithExpiration(time.Hour))
51-
52-
// the value never expires.
53-
c1.Set("bar", 2)
54-
55-
foo, ok := c1.Get("foo")
56-
if ok {
57-
fmt.Println(foo) // 1
58-
}
59-
60-
fmt.Println(c1.Keys()) // outputs "foo" "bar" may random
61-
62-
// Create a cache. key as int, value as string.
63-
c2 := cache.New[int, string]()
64-
c2.Set(1, "baz")
65-
baz, ok := c2.Get(1)
66-
if ok {
67-
fmt.Println(baz) // "baz"
68-
}
47+
// Create a simple cache. key as string, value as int.
48+
simpleCache := simple.New[string, int](simple.WithExpiration(time.Hour))
6949

70-
// Create a cache for Number constraint.. key as string, value as int.
71-
nc := cache.NewNumber[string, int]()
50+
// Create a cache for Number constraint. key as string, value as int.
51+
nc := cache.NewNumber[string, int](simpleCache)
7252
nc.Set("age", 26)
7353

7454
// This will be compile error, because string is not satisfied cache.Number constraint.
75-
// nc := cache.NewNumber[string, string]()
55+
// nc := cache.NewNumber[string, string](simpleCache)
7656

77-
incremented, _ := nc.Increment("age", 1)
57+
incremented := nc.Increment("age", 1)
7858
fmt.Println(incremented) // 27
7959

80-
decremented, _ := nc.Decrement("age", 1)
60+
decremented := nc.Decrement("age", 1)
8161
fmt.Println(decremented) // 26
8262
}
8363
```

0 commit comments

Comments
 (0)