Skip to content

Commit

Permalink
ttl is type
Browse files Browse the repository at this point in the history
parMaster committed May 31, 2024

Verified

This commit was signed with the committer’s verified signature.
thewilkybarkid Chris Wilkinson
1 parent c7d03f8 commit a0040e2
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -45,10 +45,10 @@ See the [examples](https://github.com/parMaster/mcache/tree/main/examples) direc
## API Reference
### Set

Set a key-value pair in the cache. The key must be a string, and the value can be any type, ttl is int64 value in seconds:
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", 0)
err := cache.Set("key", "value", time.Duration(0))
if err != nil {
// handle error
}
@@ -131,12 +131,12 @@ Cleanup expired key-value pairs in the cache. You can call this method periodica
cache.Cleanup()
```

WithCleanup is a functional option to the NewCache constructor that allows you to specify a cleanup interval:
`WithCleanup` is a functional option to the `NewCache` constructor that allows you to specify a cleanup interval:

```go
cache := mcache.NewCache(mcache.WithCleanup[string](time.Minute)) // cleanup every 60 seconds
```
It will basically run a Cleanup method in a goroutine with a time interval.
It will basically run a `Cleanup` method in a goroutine with a time interval.

## Tests and Benchmarks

2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ func Test_SimpleTest_Mcache(t *testing.T) {
assert.IsType(t, &Cache[string]{}, c)

testItems := []testItem{
{"key0", "value0", time.Second * 0},
{"key0", "value0", time.Duration(0)},
{"key1", "value1", time.Second * 1},
{"key2", "value2", time.Second * 20},
{"key3", "value3", time.Second * 30},

0 comments on commit a0040e2

Please sign in to comment.