File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ This offers state-of-the-art efficiency and scalability compared to other LRU-ba
1616import " github.com/scalalang2/golang-fifo/sieve"
1717
1818size := 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
2223cache.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
4667The benchmark result were obtained using [ go-cache-benchmark] ( https://github.com/scalalang2/go-cache-benchmark )
4768
You can’t perform that action at this time.
0 commit comments