Hi, we have noticed that setting and reading directly one after the other without delay in between does not work and in most runs leads to the fact that the entry that was set directly before is not found when fetching.
I have prepared a small example for this
package ristretto_test
import (
"bytes"
"testing"
"github.com/dgraph-io/ristretto"
)
func Test_Ristretto_SET_AND_GET(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1e7,
MaxCost: 1 << 30,
BufferItems: 64,
})
if err != nil {
t.Fatalf("Cache create fail = %s", err)
}
result := cache.SetWithTTL(key, val, 1, 0)
if result != true {
t.Fatalf("Value cannot be setted = %+v", result)
}
// successful with some delay
//time.Sleep(10000)
valueFromCache, ok := cache.Get(key)
if ok != true {
t.Fatalf("Value is not in cache = %+v", ok)
}
if valueFromCache == nil || bytes.Equal(valueFromCache.([]byte), []byte("doe")) == false {
t.Fatalf("Value from cache is %+v", valueFromCache)
}
}