TTL doesn’t work with Get
. It only gets cleaned up after cleanupTicker
.
The below test fails.
func TestCacheWithTTL(t testing.T) {
c, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 100,
MaxCost: 10,
IgnoreInternalCost: true,
BufferItems: 64,
Metrics: true,
})
require.NoError(t, err)
// Set initial value for key = 1
insert := c.SetWithTTL(1, 1, 1, 800 * time.Millisecond)
require.True(t, insert)
time.Sleep(100 * time.Millisecond)
// Get value from cache for key = 1
val, ok := c.Get(1)
require.True(t, ok)
require.NotNil(t, val)
require.Equal(t, 1, val)
time.Sleep(1200 * time.Millisecond)
val, ok = c.Get(1)
require.False(t, ok)
require.Nil(t, val)
}