本文介绍了在Cosmos DB中向后分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Vue前端使用c#和cosmos实现一个简单的分页系统,但是我真的不确定当用户想返回时实现分页的最佳方法.

I'm trying to implement a simple paging system with c# and cosmos on my Vue front end, but i'm not really sure the best way to implement a the paging when the user wants to go back.

对于前进,我正在使用延续令牌,因此波斯菊知道我要去哪里,但是我不确定如何将其向前推的最佳方法,或者用户是否从第1页转到3,然后返回第2页?

For going forward i'm using the continuation token, so cosmos know where i have got up to, but i'm not really sure on the best way to work this going backwards, or if the user goes from page 1 to 3, then back to page 2?

我是否必须在用户浏览项目时将结果缓存,还是有另一种方法来实现此目的?

Will i have to cache the results as the user pages through the items, or is there another way to accomplish this?

推荐答案

缓存结果很好.但我认为您也可以缓存延续令牌.

Caching the results is fine. But I think you can cache the continuation tokens as well.

只需保留页面ID和延续标记的映射即可.当您需要返回页面时,只需发出带有缓存的连续令牌的查询即可.但是,与缓存结果不同,您必须为该查询付费.

Just keep a map of page ids and continuation tokens. When you need to go back to a page, just issue a query with the cached continuation token. But, you have to pay for that query, unlike if you cache the results.

请注意,使用这种方法,您可以后退,但不能跳到多页.

Note that, with this approach you can will go back, but not jump forward multiple pages.

这篇关于在Cosmos DB中向后分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:35