7

At the moment I have document snapshots that are coming from my phone's cache. I know this from

print(document.metadata.isFromCache ? "NOT FROM NETWORK" : "FROM NETWORK");// document is a DocumentSnapshot

flutter: NOT FROM NETWORK

However I have deleted some of these documents off firestore, but they are still appearing. I would like to know if there is a way in which I can reset my cache for firestore in flutter so that all the documents are from the cloud.

Thanks for any help - much appreciated.

1
  • A lot here depends on how you read the documents in question. The document.metadata.isFromCache should typically only be true if the device has no connection to the server, in which case it is impossible for it to know that the document was deleted. If you think that doesn't explain your scenario, you might want to edit the question to include step-by-step instructions and code on how we can reproduce the problem. Commented Jan 13, 2020 at 21:52

4 Answers 4

2

It sounds like a bug if a document shows up in a query where the source document has been deleted, if the app has connectivity and can synchronize with Firestore. If you can reproduce this situation with specific steps, the Firestore team might want your bug report.

If you just want to start with a clean cache for development, you can uninstall and reinstall the app to clear the cache.

On Android, there is a system option where you can clear app data (there might be a similar iOS option as well).

Sign up to request clarification or add additional context in comments.

Comments

2

New Flutterfire SDKs behave same as web/android/ios SDKs.

let snapshot = await documentRef.get({ source: 'cache' }
if (!snapshot.exists) {
    snapshot = await documentRef.get({ source: 'server' })
}

The same can be done in new flutter Firestore sdk also, more info--> Doug Stevenson Medium post

Comments

1

It can happen when getting a PERMISSION_DENIED response from Firestore, that firestore decides to use the cached version if available.

In my case I was testing with Firestore Emulator, not sure if this will also happen when pointing to production Firestore.

To solve the issue I added persistenceEnabled: false at the moment of setting up Firestore, which in my case lives in main.dart. Setup snippet now looks like this:

   await Firestore.instance.settings(
       host: "localhost:8080",
       sslEnabled: false,
       persistenceEnabled: false,
     );

Comments

1
String host = Platform.isAndroid ? '10.0.2.2:8080' : 'localhost:8080';

  FirebaseFirestore.instance.settings = Settings(
    host: host,
    sslEnabled: false,
    persistenceEnabled: false,
  );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.