You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a value is requested from the cache right after it has expired, but before the expiration reaper has had a chance to remove it, the new expirable LRU can return a nil value but a value of true for the ok return value.
I can't tell whether this is intended or not, but it was surprising to me (I'm used to the contract being that ok == true implying that the value would be non-nil), and doesn't appear to be documented anywhere that I could find.
Here's a repro case (the timing works on my machine, but might need some tweaking or more effort simulating lots of reads around the time of expiry to work on yours):
package main
import (
"fmt""github.com/hashicorp/golang-lru/v2/expirable""time"
)
funcmain() {
cache:=expirable.NewLRU[string, *string](10, nil, 1*time.Second)
start:=time.Now()
val:="value"cache.Add("k", &val)
for {
result, ok:=cache.Get("k")
ifok&&result==nil {
fmt.Printf("got result = nil, ok = true after %v\n", time.Since(start))
return
}
}
}
When I run this I get:
❯ go run main.go
got result = nil, ok = true after 1.000000209s
The text was updated successfully, but these errors were encountered:
When a value is requested from the cache right after it has expired, but before the expiration reaper has had a chance to remove it, the new expirable LRU can return a
nil
value but a value oftrue
for theok
return value.I can't tell whether this is intended or not, but it was surprising to me (I'm used to the contract being that
ok == true
implying that the value would be non-nil), and doesn't appear to be documented anywhere that I could find.Here's a repro case (the timing works on my machine, but might need some tweaking or more effort simulating lots of reads around the time of expiry to work on yours):
When I run this I get:
The text was updated successfully, but these errors were encountered: