Skip to content

Commit 70c5735

Browse files
committed
docs: updated
1 parent 2c101cf commit 70c5735

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This offers state-of-the-art efficiency and scalability compared to other LRU-ba
1616
import "github.com/scalalang2/golang-fifo/sieve"
1717

1818
size := 1e5
19-
cache := sieve.New[string, string](size)
19+
ttl := 0 // 0 means no expiration
20+
cache := sieve.New[string, string](size, ttl)
2021

2122
// set value under hello
2223
cache.Set("hello", "world")
@@ -42,6 +43,26 @@ if removed {
4243
}
4344
```
4445

46+
## Expiry
47+
```go
48+
import "github.com/scalalang2/golang-fifo/sieve"
49+
50+
size := 1e5
51+
ttl := time.Second * 3600 // 1 hour
52+
cache := sieve.New[string, string](size, ttl)
53+
54+
// this callback will be called when the element is expired
55+
cahe.SetOnEvict(func(key string, value string) {
56+
fmt.Printf("key: %s, value: %s was evicted", key, value)
57+
})
58+
59+
// set value under hello
60+
cache.Set("hello", "world")
61+
62+
// remove all cache entries and stop the eviction goroutine.
63+
cache.Close()
64+
```
65+
4566
## Benchmark Result
4667
The benchmark result were obtained using [go-cache-benchmark](https://github.com/scalalang2/go-cache-benchmark)
4768

0 commit comments

Comments
 (0)