A simple thread-safe memoizer for Go using only the standard library.
Supports Go 1.18 and higher due to the use of generics.
func expensiveFunction() (*any, error) {
// ...
}
var memoized = memoizer.New(expensiveFunction, 10*time.Second)
for i := 0; i < 50; i++ {
value, err := memoized.Get()
// ...
}
go get github.com/LightningDev1/go-memoizer
See config example for a complete example program.