I am starting with Firestore. I've read docs and tutorials about the offline data persistence but I have not really clear if Firestore downloads data again even if the content hasn't been modified. For example, if I have a query where the results will be updated once a week and I don't need that the app download the content again until the changes were made, what is the best way in terms of efficiency to write the code? Thanks!
相关问题
- Firebase security rules difference between get() a
- Firebase firestore not working with Angular Univer
- Firestore limit writing access per time
- How to download and run a .exe file c#
- MappedListIterable is not a SubType
相关文章
- Is there a google API to read cached content? [clo
- Firestore Update a document field Using Rest API
- How to combine Firestore orderBy desc with startAf
- AWS API Gateway caching ignores query parameters
- Check if url is cached webview android
- WebView's LOAD_NO_CACHE setting still saves fi
- Firestore + cloud functions: How to read from anot
- QML Loader not shows changes on .qml file
You want to use the "snapshot listener" API to listen to your query: https://firebase.google.com/docs/firestore/query-data/listen#listen_to_multiple_documents_in_a_collection
Here's some JavaScript as an example:
The first time you attach this listener Firestore will access the network to download all of the results to your query and provide you with a query snapshot, as you'd expect.
If you attach the same listener a second time and you're using offline persistence, the listener will be fired immediately with the results from the cache. Here's how you can detect if your result is from cache or local:
After you get the cached result, Firestore will check with the server to see if there are any changes to your query result. If yes you will get another snapshot with the changes.
If you want to be notified of changes that only involve metadata (for example if no documents change but
snapshot.metadata.fromCache
changes) you can useQueryListenOptions
when issuing your query: https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/QueryListenOptions