fetchObjStream vs fetch

#1

I could see that their names, function parameter, function return value are different. But both have document Fetches multiple obj instances based on a specification. Only objs that the caller is authorized to fetch will be returned.

So what are difference behind the scenes? in which case we should use fetch, and in which case we should use fetchObjStream?

0 Likes

#2

fetchObjStream returns a Stream which means that it will not materialize the values of the fetch results in memory. It will read those values one at a time keeping the memory footprint low. It is much more memory efficient to use this api when you have to iterate over the objs one at a time.

fetch will return the same results, except that it will materialize all the objects in memory. This could easily cause memory to blow up / give out of memory exceptions if you are expecting a large number of objects.

0 Likes