Achieve good paging using objectify

喜欢而已 提交于 2019-12-24 07:58:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!