Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何删除本地缓存中的可用状态?_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 如何删除本地缓存中的可用状态?

Java 如何删除本地缓存中的可用状态?,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,因此,我正在开发一个使用firebase的firestore的应用程序,我想知道这是否可行,因为我不想让我的应用程序检查服务器中不再存在的数据。 示例: collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() { @Override public void onEvent(QuerySnapshot snapshots, FirebaseFirestoreEx

因此,我正在开发一个使用firebase的firestore的应用程序,我想知道这是否可行,因为我不想让我的应用程序检查服务器中不再存在的数据。

示例:

collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(QuerySnapshot snapshots, FirebaseFirestoreException e) {
            for (DocumentSnapshot snapshot : snapshots) {
                System.out.println(snapshot.getId());
                // This prints document IDs of documents that were deleted
                // from the collection when the app was not running
            }
        }
    });
collectionReference.addSnapshotListener(新的EventListener(){
@凌驾
public void OneEvent(QuerySnapshot快照,FireBaseFireStore异常e){
用于(文档快照快照:快照){
System.out.println(snapshot.getId());
//这将打印已删除文档的文档ID
//应用程序未运行时从集合中删除
}
}
});

使用
DocumentSnapshot.exists()
筛选仅存在于服务器中的快照不起作用


更多信息请访问:

初始状态可以直接来自服务器,也可以来自本地缓存。如果本地缓存中存在可用状态,则查询快照最初将使用缓存的数据填充,然后在客户机了解到服务器的状态后使用服务器的数据更新


您可以通过检查快照的元数据来确定快照是否来自缓存

返回一个
SnapshotMetadata
对象。 如果快照来自缓存,则返回布尔值

如果您希望在元数据更改时收到通知(这样您就可以知道
isFromCache()
是否更改),那么您必须在添加侦听器时传递选项:

   // Create options
   QueryListenOptions options = new QueryListenOptions().includeDocumentMetadataChanges();

   // Pass them when you add the listener
   collectionReference.addSnapshotListener(options, new EventListener<QuerySnapshot>() {
       // ...
   });
//创建选项
QueryListenOptions=new QueryListenOptions()。includeDocumentMetadataChanges();
//添加侦听器时传递它们
collectionReference.addSnapshotListener(选项,new EventListener(){
// ...
});
有关详细信息,请参阅文档