The following test case will fail. Seems there's no way to keep an entry alive.
IMO, Peek retrieves data without updating its TTL, but Get does. So if we keep Get its value before it expires, wee keep it alive. Am I correct?
func TestExpirableLRUKeepAlive(t *testing.T) {
cache := expirable.NewLRU[string, string](5, nil, time.Millisecond*100)
cache.Add("A", "Apple")
start := time.Now()
for range time.NewTicker(time.Millisecond * 10).C {
elapsed := time.Since(start).Milliseconds()
if v, ok := cache.Get("A"); !ok || v != "Apple" {
t.Fatalf("entry expired after %dms", elapsed)
}
if elapsed > 500 {
break
}
t.Logf("so far so good: %dms", elapsed)
}
}