-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Is your feature request related to a problem? Please describe.
For GetOrFetchBatch, have you thought about switching to an iterator-based approach?
There are different "delivery times" for items from the in-memory cache, distributed cache and the fetch function.
Depending on the use case it could be beneficial to make partial results available to the caller so that they can already be processed while the other items are still getting fetched. This could reduce API latencies or throughput times.
Describe the solution you'd like
Use golang's iterators either directly in GetOrFetchBatch or offer an alternative function.
Seq2[K, V any] allows iterating over pairs of values which is what GetOrFetchBatch aggregates and merges anyway from the different configured sources.
maps.Collect(..) can create the current result type (map[string]V) directly from this Seq2 iterator. So both response styles could easily be offered.
Additional context
See
https://pkg.go.dev/iter#hdr-Iterators
https://pkg.go.dev/iter#Seq2
Jochen Mehlhorn jochen.mehlhorn@mercedes-benz.com, Mercedes-Benz Tech Innovation GmbH