Does firebase web client download data every time I subscribe for a certain database path?

假如想象 提交于 2021-01-29 13:09:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!