Skip to content

Commit

Permalink
WithCleanup option explained
Browse files Browse the repository at this point in the history
  • Loading branch information
parMaster committed Aug 4, 2023
1 parent 53ff554 commit 2a6a617
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,12 @@ Cleanup expired key-value pairs in the cache. You can call this method periodica
cache.Cleanup()
```

If you want to cleanup expired key-value periodically, you can run the `Cleanup` method in a goroutine with a time interval:
WithCleanup is a functional option to the NewCache constructor that allows you to specify a cleanup interval:

```go
go func() {
for {
cache.Cleanup()
time.Sleep(1 * time.Minute) // run every minute
}
}()
cache := mcache.NewCache(mcache.WithCleanup(60)) // cleanup every 60 seconds
```
It will basically run a Cleanup method in a goroutine with a time interval.

## Tests and Benchmarks

Expand Down

0 comments on commit 2a6a617

Please sign in to comment.