使用Google App Engine的分页技术 [英] Pagination Techniques using Google App Engine

查看:263
本文介绍了使用Google App Engine的分页技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GAE(Java)的Cursor功能为我的网站实现分页。但是,只有一个向前光标;反向游标不是从App Engine SDK 1.4.0开始实现的。因此,为了实现上一页的功能,建议我将游标保存在memchache中。但我的问题是 - 当新记录添加到数据存储区时,各个页面的旧游标将无效。如何处理这种情况?



有没有人在Java之前已经用游标实现了这个功能?请仔细详细说明这个算法。



此外,我还没有看到一个具体的实现/例子在Java。

解决方案

如果你的解决方案是ajax-y,你可以保持光标



当数据被添加(或删除/更改)时,旧游标不会失效。您仍然可以使用它们。在你的情况下,它们基本上代表页面上的第一个项目。因此,唯一可能发生的是,如果您在第3页的结果,然后向后浏览,然后转发,您可能看不到完全相同的实体,您以前在第3页。



例如,如果您从第2页转到第3页:




  • 第2页(cursor = x2)results:[d,e ,f,...,g]

  • 第3页(cursor = x3)results:[h,i,j,...] ul>

    然后,如果'e'被删除。向后,第2页(cursor = x2)现在将显示[d,f,...,g,h],并且我们更新游标x3,因为它改变了(我们在第2页的每次fetch接下来,第3页现在将有[i,j,...]



    同样,如果e2 2,我们将有[d,e,e2,f,...]和x3被更新。第三页将包含[g,h,i,j,...]



    唯一的注意事项是第一页不应该使用游标case元素在第一个之前添加),并且您应该总是允许用户尝试去到下一页,以便在最后一个结果之后添加元素。



    所以页码不会非常具体,但它们不能真正处理分页数据,而不是可以更新。一个诀窍是不使用页码,但将页面标记为以元素x开头的数据或类似的东西。



    我不知道任何实现,它应该很漂亮地前进来实施。在文档中描述了光标功能: http:// code .google.com / appengine / docs / java / datastore / queries.html#Query_Cursors


    I want to implement pagination for my website using the Cursor feature of GAE (Java). However, there is only a forward cursor ; backward cursors are not implemented as of App Engine SDK 1.4.0. So, to implement a previous page functionality, it is suggested that I store the cursor page wise in memchache. But my question is - when new record gets added into the datastore, the old cursors for respective pages would become invalid. How do I handle such situations?

    Is there anyone who has already implemented this functionality with cursors in Java before? Kindly elaborate the algorithm for this.

    Also, I haven't seen a concrete implementation/ example for the same in Java. Could you please share some links if possible.

    解决方案

    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

    这篇关于使用Google App Engine的分页技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆