0

In my app I need to get a lot of documents everytime a user starts the app.

This documents can only be edited by the user himself and not from other users. So the only way that the documents from Firestore differ from cache is if the user did logged in on another device with his account where the newest data is not cached yet.

Now I search for a solution to get these documents from cache by default to save reads and only get the documents from Firestore again if they differ from cache.

Is this possible with Firestore?

Note: I am using Flutter for app development

Dalon
  • 566
  • 8
  • 26

1 Answers1

1

This is nothing that Firestore supports by default. You could achieve this by defining one extra "status" document for each user. This document should log the latest user activity on all devices. You can then check and compare the datasets on firestore with your local cache (maybe use hashing) to determine if you need to fetch new data.

Jannik
  • 635
  • 1
  • 6
  • 14
  • Great answer, Jannik. I find it easiest to self-answer this question by wondering how the SDK will know that there is an update to a document it has in the cache. If that requires it to check that document in the server, that requires a charged document read. So the only way to make this cheaper is to not have to check each document, e.g. by querying with some cutoff timestamp of when you last read and can compare that with a `lastUpdated` field in the documents. – Frank van Puffelen Jan 04 '23 at 15:04