Firestore-具有数据分页的缓存行为 [英] Firestore - Caching behaviour with data pagination

查看:35
本文介绍了Firestore-具有数据分页的缓存行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读文档时,我实现了分页,但是我对firestore的本地缓存与分页的行为感到困惑.假设我的查询是要获取前20个文档.为了进行测试,我将页面大小更改为25,然后再次启动应用程序以获取完全相同的20个文档(之前已缓存)+ 5个新文档.在这种情况下,缓存机制在读取次数方面将如何表现?它会花费5次新阅读还是25次新阅读?我尝试了几次,看看Firebase控制台的统计信息是否可以帮助您,但那里的读取计数没有意义.

Going through the documentation, I implemented pagination but I am confused how firestore's local cache behave with pagination. Suppose my query is to get first 20 documents. For testing, I change paging size to 25 and start application again to get exactly same 20 documents(cached before) + 5 new documents. How does the cache mechanism will behave with respect to number of reads in this case? Will it cost 5 new reads or 25 new reads? I tried several times to see if firebase console stats could help but the read counts there made no sense.

调用前的控制台状态显示为68,但第二次查询后,控制台状态应为(68 + 5)或(68 + 25),而是显示76个读操作.这些统计数据并没有帮助我弄清楚行为.

Console stats before the call show 68 reads but after second query it should be either (68+5) or (68+25), instead it shows 76 read operations. These stats didn't help me out to figure out the behavior.

推荐答案

缓存仅在以下情况下对 any 查询有效:

The cache only has an effect for any query when:

  1. 客户端离线
  2. 查询专门使用缓存作为源

在所有其他情况下,不使用缓存,并且服务器发送所有文档.每个文档都会被读取并发送给客户端,您将为所有这些文档的读取付费.分页根本不会改变这种行为.

All other cases, the cache is not used, and the server sends all documents. Each document is read and sent to the client, and you will be billed for all those document reads. Pagination doesn't change this behavior at all.

阅读这可以了解有关缓存工作原理的更多信息.

这篇关于Firestore-具有数据分页的缓存行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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