问题
In my angular app, I use AngularFire
to access firebase realtime database.
I have following method to retrieve entities in a certain database path.
private db: AngularFireDatabase;
public getAll(): Observable<Item[]> {
return this.db.list<Item>('some/db/path').valueChanges();
}
If I call above method multiple times, does the data get downloaded multiple times from server, or firebase client uses a local cache second time onward?
If data gets downloaded multiple times, is there any way I can instruct firebase client to use local caching?
回答1:
The Firebase Realtime Database client deduplicates listeners. That means that:
this.db.list<Item>('some/db/path').valueChanges();
this.db.list<Item>('some/db/path').valueChanges();
The above code will only download the data once initially, and only download the delta once for each change.
Note that you can check this for yourself by looking at the Web Socket traffic in the network panel of your browser.
来源:https://stackoverflow.com/questions/52164921/does-firebase-web-client-download-data-every-time-i-subscribe-for-a-certain-data