Pagination Techniques using Google App Engine

这一生的挚爱 提交于 2019-12-03 12:41:23

If your solution is ajax-y, you can keep the cursor (as a string) in an array on the client side in javascript, so you don't need to store it in memcache.

When data gets added (or deleted/changed) the old cursors don't become invalidated. You can still use them. In your case, they basically represent the first item on a page. So the only thing that might happen is if you are on page 3 of results and navigate back and then forward, you might not see the exact same entities you did before on page 3.

For example if you went from page 2 to page 3:

  • Page 2 (cursor=x2) results: [d,e,f,...,g]
  • Page 3 (cursor=x3) results: [h,i,j,...]

Then, if 'e' got deleted. Going backwards, page 2 (cursor=x2) will now show [d,f,...,g,h], and we update cursor x3 since it changed (we check it after each fetch() for page 2). Going forward, page 3 will now have [i,j,...]

Similarly, if instead 'e2' got added after 'e', going back to page 2 we would have [d,e,e2,f,...] and x3 gets updated. And going forward, page 3 will contain [g,h,i,j,...]

The only caveat is the first page should never use a cursor (in case elements get added before the first one), and you should always allow the user to "try" to go to the next page, in case elements got added after the last result.

So page numbers won't be very specific, but they can't really be when dealing with paged data than can be updated. One trick is to not use page numbers, but label the pages as "data starting with element x" or something like that.

I don't know any implementations, but it should be pretty strait forward to implement. Cursor functionality is described pretty well in the docs: http://code.google.com/appengine/docs/java/datastore/queries.html#Query_Cursors

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