Closed Scratch-net closed 3 years ago
Fetch is thread-safe in that, you aren't going to deadlock or corrupt anything within the ccache library, but the fetch
func that's passed in will be called concurrently. I'm not 100% sure if this is something the library itself should handle, because it isn't clear if there's 1 correct way to handle this for all cases.
But, it should be pretty easy to handle in the app (using something like https://pkg.go.dev/golang.org/x/sync/singleflight)
Thanks!
If I call Fetch() simultaneously from multiple goroutines and the fetch func is rather slow, then it keeps being called until one of the calls returns. So, it looks like Fetch() is not thread-safe