go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

cache component may cache expired data

Open zhongyuanjia opened this issue 1 year ago • 5 comments

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

zhongyuanjia avatar Mar 09 '23 10:03 zhongyuanjia

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.

kevwan avatar Mar 09 '23 13:03 kevwan

图片

Using updating placeholders can solve this problem. I submitted an PR, you can see if it is feasible.

zhongyuanjia avatar Mar 09 '23 17:03 zhongyuanjia

@kevwan

zhongyuanjia avatar Mar 16 '23 11:03 zhongyuanjia

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@kevwan

Issues-translate-bot avatar Mar 16 '23 11:03 Issues-translate-bot

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Mar 22 '24 01:03 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 26 '24 01:06 github-actions[bot]