eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.4k stars 193 forks source link

Avoid parallel running a load function for the same key #242

Closed advoretsky closed 4 months ago

advoretsky commented 4 months ago

It's worth to implement parallel run of the load function for the same key on cache miss. Without it under load cache may proxy multiple requests to a backend for the same key.

eko commented 4 months ago

Thank you for fixing this. I consider this issue can be closed

wchargin commented 2 months ago

adding search keywords: LoadableCache, loader called multiple times. (I'm running v4.1.5 and it took me a while to track down this bug; I did an issue search but didn't find this until I git blamed the singleflight lines in v4.1.6 and saw that they're new.)