Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Adjust Firestore cache size with AngularFire

I'm trying to figure out the best way to enable Firestore persistence and adjust the cache size using AngularFire.

Firebase documentation suggest we do it like this:

firebase.firestore().settings({
     cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED
});

AngularFire does not mention adjusting such settings, but digging into the code it looks like you can pass an object of type "firebase.firestore.PersistanceSettings" in as such:

AngularFirestoreModule.enablePersistence({
      experimentalForceOwningTab: true,
      synchronizeTabs: true,
}),

However, those are the only two properties allowed in the PersistanceSettings type.

I tried creating a constructor in app.module.ts and doing things according to the Firebase documentation but I'm not even sure if it is working.

export class AppModule {
  constructor() {
    firebase.firestore().settings({
      cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED,
    });
  }
}

How do I check what the cache size settings are at run time? Am I doing it right?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

CACHE_SIZE_UNLIMITED is -1, to be set preferably in app.module.ts:

const settings: firebase.firestore.Settings = {
  cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED
};
firebase.firestore().settings(settings);

There doesn't seem to be a method to read the settings... cacheSizeBytes is already known.
And one probably cannot change the value of cacheSizeBytes either, once having connected.

about 4 years ago · Juan Pablo Isaza Report

0

Searching around the AngularFire documentation, I found their document related to offline storage. It explains how to enable file persistence in your app and also that you can test whether a document is retrieved from cache or Firestore using the fromCache property.

To check whether you are receiving data from the server or the cache, use the fromCache property on the SnapshotMetadata in your snapshot event. If fromCache is true, the data came from the cache and might be stale or incomplete. If fromCache is false, the data is complete and current with the latest updates on the server.

As for setting the cache size for Firestore, it appears that the only way is what you have been trying and it is a variable set in the Firestore instance properties. Here are full samples from the documentation related to setting the cache size and enabling persistence.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!