disable cache on firestore in Flutter

Viewed 1920

How to disable get/stream data from cache on firestore?

I saw this article. this feature is by default enable PersistenceEnabled

Is it a clear cache in this way?

void main() async {
  await Firebase.initializeApp();
  await FirebaseFirestore.instance.clearPersistence();

OR

Is it need to add to every query?

  Future<List<BookModel>> _getBooks() async {
    await FirebaseFirestore.instance.clearPersistence();
    return _db.collection('books')...  
    }

OR

How to disable cache on firestore all time?

Is it correct?

void main() async {
  await Firebase.initializeApp();
  FirebaseFirestore.instance.settings = 
Settings(
persistenceEnabled: false,
cacheSizeBytes: ?,//is it need add this fields too?
host: ?,
sslEnabled: ?

);

1 Answers

Calling clearPersistence clears the local cache, but doesn't disable it. So any database calls after that will start populating the local cache again.

To disable the client from using the cache, you'll need to set persistenceEnabled to false when the app starts.

Related