Florian K
Florian K

Reputation: 2148

Cloud firestore keep in cache queries called several times?

What happens if I call this query once which is used in a StreamBuilder which wrap a ListView :

Firestore.instance
          .collection('users')
          .orderBy('createdAt', descending: true)
          .limit(3)
          .snapshots();

and then I run this same query a second time but with a limit of 6 :

Firestore.instance
          .collection('users')
          .orderBy('createdAt', descending: true)
          .limit(6)
          .snapshots();

Does the 3 first snapshots are called a second time or kept in cache ? Does the StreamBuilder rebuild all the ListView ?

Upvotes: 0

Views: 122

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

The second query will fetch all 6 documents again. None of them will not come from cache, so they will all be billed as reads on the server, and take time to transfer. The only way query results will come from cache is if the client app is offline, or you specify a query source of cache using getDocuments and specify a Source of cache.

Upvotes: 1

Related Questions