问题
I'm using objectify cursors to achieve basic paging, basically creating a more
button.. How best do you achieve paging using objectify for building links that allow users to go forward and backwards. Something more like a page list..
1, 2, 3, 4, more
回答1:
Your best bet is probably to fetch the keys for the entire result set and stash it in a session or in javascript. Each next/previous can load the next item in your list by id. Loading by id is very cheap. You can cache the full query results in memcache as long as it's not too large but that's going to depend on what kind of objects you're fetching.
回答2:
You can use cursors to create paging by one page forward and backwards, via FetchOptions.startCursor(..) and FetchOptions.endCursor(..)
To create more direct paging links you will have to use FetchOptions.limit(..) and FetchOptions.offset(..).
Note that offset(..)
can be very costly as it fetches all entities that come before given page. So, depending on usage and size of the whole set, you might be better off by preloading and caching a set of keys. Or better, replace paging with search.
来源:https://stackoverflow.com/questions/9726232/achieve-good-paging-using-objectify