Skip to content

Commit

Permalink
fix and improve Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
parMaster committed Dec 18, 2024
1 parent 197bd05 commit e9e02a3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ Create a new cache instance using the `NewCache` constructor, and use it to perf
```go
cache := mcache.NewCache[string]()
data, err := cache.Get("key")
if err != nil {
data = ExpensiveFunctionCall()
cache.Set("key", data, 5*time.Minute) // cache data for 5 minutes
if err == nil {
return data
}
data = ExpensiveFunctionCall()
cache.Set("key", data, 5*time.Minute) // cache data for 5 minutes
```
## Examples

Expand All @@ -61,13 +62,10 @@ type Cacher[T any] interface {

### Set

Set a key-value pair in the cache. The key must be a `string`, value type defined during cache creation, ttl is `time.Duration` type. If ttl is 0, the key-value pair will not expire.:
Set a key-value pair in the cache. The key must be a `string`, value type defined during cache creation, `ttl` is `time.Duration` type. If `ttl` is 0, the key-value pair will not expire.:

```go
err := cache.Set("key", "value", time.Duration(0))
if err != nil {
// handle error
}
cache.Set("key", "value", time.Duration(0))
```

If the key already exists and is not expired, `false` will be returned. If the key exists but is expired, the value will be updated.
Expand Down

0 comments on commit e9e02a3

Please sign in to comment.