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.42k stars 192 forks source link

I think it's better for Loadalbe to support singleflight? #192

Closed yflau closed 1 year ago

yflau commented 1 year ago

With golang.org/x/sync/singleflight, it provides a duplicate function call suppression mechanism, maybe it's better for gocache Loadable to support this feature builtin.

eko commented 1 year ago

Hi @yflau,

Thank you for your proposal but I think in our case it will not fit well.

Indeed, as the package singleflight name suggests, it will make a “single” call and never call again unless the key is forgotten.

In our case we don’t know when the key is forgotten because it will be expired by the cache engine and so we will reload it into the cache. But we will always check for the key to exist in the cache engine.

I don’t see the benefits of using singleflight here but if you want to provide an implementation that proves me I am wrong please feel free to submit a pull request with that.

Thank you!

eko commented 1 year ago

Closing for now but feel free to reopen.