Skip to content

Commit 7859dd0

Browse files
committed
fix: update eviction example
1 parent 1fe7a91 commit 7859dd0

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

__examples/eviction/eviction.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import (
1212
"github.com/hyp3rd/hypercache/pkg/backend"
1313
)
1414

15-
const cacheCapacity = 10
15+
const (
16+
cacheCapacity = 10
17+
evictionInterval = 10 * time.Second
18+
evictionIntervalSlippage = 65 * time.Second
19+
)
1620

1721
// This example demonstrates how to setup eviction of items from the cache.
1822
func main() {
1923
log.Println("running an example of eviction with a background 3 seconds interval")
20-
executeExample(constants.DefaultEvictionInterval)
24+
executeExample(evictionInterval)
2125

2226
log.Println("running an example with background eviction disabled and proactive eviction enabled")
2327
executeExample(0)
@@ -81,8 +85,8 @@ func executeExample(evictionInterval time.Duration) {
8185
}
8286

8387
if evictionInterval > 0 {
84-
fmt.Fprintln(os.Stdout, "sleeping to allow the eviction loop to complete", evictionInterval+2*time.Second)
85-
time.Sleep(evictionInterval + 2*time.Second)
88+
fmt.Fprintln(os.Stdout, "sleeping to allow the eviction loop to complete", evictionInterval+evictionIntervalSlippage)
89+
time.Sleep(evictionInterval + evictionIntervalSlippage)
8690
log.Println("listing all items in the cache the eviction is triggered")
8791

8892
list, err := cache.List(context.TODO())

0 commit comments

Comments
 (0)