问题
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.
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.
回答1:
The cache only has an effect for any query when:
- The client is offline
- The query specifically uses the cache as a source
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.
Read this to learn more about how the cache works.
来源:https://stackoverflow.com/questions/62471082/firestore-caching-behaviour-with-data-pagination