sturdyc icon indicating copy to clipboard operation
sturdyc copied to clipboard

Use iterator in GetOrFetchBatch

Open jo-me opened this issue 10 months ago • 1 comments

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 [email protected], Mercedes-Benz Tech Innovation GmbH

Provider Information

jo-me avatar Apr 03 '25 09:04 jo-me

Hi, this isn’t something I've considered yet! If enough people want this functionality, I might add it - but it would have to be through new methods to avoid breaking the current API.

viccon avatar Apr 22 '25 07:04 viccon