gocache icon indicating copy to clipboard operation
gocache copied to clipboard

[Suggestion] Ristretto Set may fail and it's the expected behavior

Open Yiling-J opened this issue 1 year ago • 0 comments

From Ristretto's Readme FAQ:

As for "shortcuts," the only thing Ristretto does that could be construed as one is dropping some Set calls

So both set and setTags may return false when using Ristretto. Maybe better to mention it in readme or do something in code.

And here is a simple parallel benchmark to demonstrate that:

func BenchmarkRistrettoSetParallel(b *testing.B) {
	ctx := context.Background()

	client, err := ristretto.NewCache(&ristretto.Config{
		NumCounters: 1000,
		MaxCost:     100,
		BufferItems: 64,
	})
	if err != nil {
		panic(err)
	}
	store := NewRistretto(client, nil)

	b.RunParallel(func(pb *testing.PB) {
		i := 0
		for pb.Next() {
			key := fmt.Sprintf("test-%d", i)
			value := []byte(fmt.Sprintf("value-%d", i))
			err := store.Set(ctx, key, value, lib_store.WithTags([]string{fmt.Sprintf("tag-%d", i)}))
			if err != nil {
				fmt.Print("x")
			}
			i++
		}
	})
}

you'll see some "x" when running it

Yiling-J avatar Apr 15 '23 11:04 Yiling-J