There is a REST (like) API that returns a list of results. The results are obtained from the SQL query. It is necessary to implement paging, i.e. the ability to return only a certain number of items from the requested.
The solution "in the forehead" - every time to fulfill the request and read the necessary records from the cursor, it works extremely slowly.
Caching results in the API and storing until the next call violates the principle of statelessness.
What other approaches to the implementation of this functionality can be advised?
Database - PostgreSQL.