【问题标题】:clear firebase cache with keepSynced(true) not working使用keepSynced(true)清除firebase缓存不起作用
【发布时间】:2019-03-07 10:39:24
【问题描述】:

我需要保持我的 firebase 数据库同步,所以我做了一些搜索,发现我可以使用 keepsynced(true) 因为默认情况下,Firebase 会在缓存中保留 10mb 数据,如果它进一步增长,它将被新数据取代 所以我就这样使用它 (在故障的节点应用上使用 firebase)

 var locationRef = admin
    .database()
    .ref()
    .child("locations");
 locationRef.keepSynced(true);
 locationRef.once('value').then(function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
        var childKey = childSnapshot.key;
        var childData = childSnapshot.val();
          console.log(childData);
          presseLocations.push(childData)
                });

但我收到此错误:

 locationRef.keepSynced is not a function

有什么想法吗?

【问题讨论】:

    标签: javascript firebase firebase-realtime-database


    【解决方案1】:

    为了保持数据同步,您应该使用 on() 而不是 once(),因为使用 once() 从数据库中获取值一次,而使用 on() 会继续侦听数据的更改,直到您调用 off( )

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 2021-11-02
    • 2019-05-27
    • 2018-02-12
    相关资源
    最近更新 更多