Back to problems

Design Pagination API

Object-Oriented Programming · Lyft · Medium

Sequential Buffering with Lazy Page Fetching The external data source only hands us one page at a time, and we don't know how many total items exist or how many items are on any given page. What we can do is keep a local buffer of the current page and a pointer that tells us which item we'll hand out next. When getNext(n) is called, we first drain what's left in the buffer; if that's not enough, we request the next page from the external API, append its contents to the…

Checking your access…