Cassandra C#驱动程序中的向后分页 [英] Backward paging in cassandra c# driver

查看:98
本文介绍了Cassandra C#驱动程序中的向后分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用cassandra来存储数据库.我们无法在c#datastax驱动程序中向后/向前翻页.谁能建议一种在MVC项目中分页结果的方法.

We are tryint to use cassandra to store database. We are not able to page backward/forward in c# datastax driver. Can anyone suggest a methodology to page results in MVC project.

推荐答案

您可以使用

You can use the manual paging feature of the C# driver to page through results from Cassandra. Basically it works like this:

  1. 在查询首页之前,请在要获取首页的语句上调用SetAutoPage(false)SetPageSize(pageSize).
  2. 从Cassandra中选择结果的第一页.查询返回的RowSet将具有PagingState属性.将分页状态保存在某个地方(例如,在会话存储或Cookie中)
  3. 稍后,当您要获取下一页时,请从存储它的位置检索PagingState.
  4. 在查询下一页之前,请在语句上调用SetAutoPage(false)SetPagingState(yourPagingStateFromStorage)以获得下一页.
  5. 对后续页面重复步骤2-4.
  1. Before querying the first page, call SetAutoPage(false) and SetPageSize(pageSize) on your statement that's going to get the first page.
  2. Select the first page of results from Cassandra. The RowSet that's returned from the query will have a PagingState property. Save that paging state somewhere (for example, in Session storage or a Cookie)
  3. Later, when you want to get the next page, retrieve the PagingState from where you stored it.
  4. Before you query for the next page, call SetAutoPage(false) and SetPagingState(yourPagingStateFromStorage) on the statement to get the next page.
  5. Repeat steps 2-4 for subsequent pages.

棘手的部分是向后向后分页.如果您要在用户界面中缓存页面调度的结果(即,每次有人单击按钮以转到下一页/上一页时,都不会刷新整个页面),则这不是问题,因为向后分页实际上只是在移动向后浏览已查询并已缓存的数据(可能在JavaScript代码的数组中).

The tricky part is paging backwards. If you're caching the results of your paging in your UI (i.e. not doing a full page refresh every time some clicks a button to go to the next/previous page), this isn't an issue since paging backwards is really just moving backwards through the data you've already queried and have cached (probably in an array in your JavaScript code).

如果您每次有人点击翻阅结果时都进行整页刷新,那么您需要保留所有页面中的PagingState,直到您确定他们已完成分页(即存储多个分页)在会话或Cookie等内容中声明值).这样,如果有人向后翻页,您只需查找上一页的分页状态令牌,然后在查询中使用它即可.

If you are doing a full page refresh every time someone clicks to page through results, then you'll need to keep the PagingState from all pages around until you're sure they're done paging (i.e. store multiple paging state values in something like Session or a cookie). That way, if someone pages backwards you can just lookup the paging state token for that previous page and use it in your query.

注意:如果您处于整页刷新状态,则还可以将分页状态作为querystring参数传递给周围.例如,使链接指向下一页"/some/page?pagingState = PAGING_STATE_FROM_ROWSET_CURRENTLY_DISPLAYED",然后进行向后分页与浏览器的后退按钮相同.

Note: If you're in the full page refresh situation, you might also be able to pass the paging state around as a querystring parameter. For example, make the link to the next page "/some/page?pagingState=PAGING_STATE_FROM_ROWSET_CURRENTLY_DISPLAYED" and then having backwards paging just do the same thing as the browser's back button.

这篇关于Cassandra C#驱动程序中的向后分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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