go-zero
go-zero copied to clipboard
cache component may cache expired data
Describe the bug

From the above figure we can see that in extreme cases the cache will cache expired data
To Reproduce
go func() {
c.Take(key, val, func() (interface{}, error) {
val := getFromDB(ctx)
// Perform some time-consuming operations, or GC jitter.
time.Sleep(time.Second)
return val
})
}()
go func() {
updateDB()
c.Del(key)
}()
Expected behavior Dont cache expired data
Environments (please complete the following information):
- OS: Macos
- go-zero version 1.5.0
I talked about this scenario in my presentations. It's a rarely happened case. It's hard to solve it well without bringing the system too complicated.

Using updating placeholders can solve this problem. I submitted an PR, you can see if it is feasible.
@kevwan
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@kevwan
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.