每当我订阅某个数据库路径时,firebase Web客户端都会下载数据吗? [英] Does firebase web client download data every time I subscribe for a certain database path?

查看:50
本文介绍了每当我订阅某个数据库路径时,firebase Web客户端都会下载数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的角度应用程序中,我使用 AngularFire 访问Firebase实时数据库.

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();
}

如果我多次调用上述方法,是否会多次从服务器下载数据,或者Firebase客户端第二次使用本地缓存?

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?

如果多次下载数据,有什么方法可以指示Firebase客户端使用本地缓存?

If data gets downloaded multiple times, is there any way I can instruct firebase client to use local caching?

推荐答案

Firebase实时数据库客户端对侦听器进行重复数据删除.这意味着:

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.

请注意,您可以通过在浏览器的网络面板中查看Web套接字流量来自行检查.

Note that you can check this for yourself by looking at the Web Socket traffic in the network panel of your browser.

这篇关于每当我订阅某个数据库路径时,firebase Web客户端都会下载数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆