Google cloud firestore 禁用Firestore查询中的缓存
我正在运行firestore查询以获取数据,但该查询将从先前的缓存数据查询返回数据,然后在服务器的第二次传递中返回其他数据(之前未查询)。是否有一种方法可以禁用firestore查询的缓存,以便每次查询时请求都会转到DBGoogle cloud firestore 禁用Firestore查询中的缓存,google-cloud-firestore,angularfire,Google Cloud Firestore,Angularfire,我正在运行firestore查询以获取数据,但该查询将从先前的缓存数据查询返回数据,然后在服务器的第二次传递中返回其他数据(之前未查询)。是否有一种方法可以禁用firestore查询的缓存,以便每次查询时请求都会转到DB this.parts$ = this.db.collection<OrderBom>('OrderBom', ref => { let query : firebase.firestore.Query = ref; query = qu
this.parts$ = this.db.collection<OrderBom>('OrderBom', ref => {
let query : firebase.firestore.Query = ref;
query = query.where('orderPartLC', '==', this.searchValue.toLowerCase());
return query;
}).valueChanges();
this.parts$=this.db.collection('OrderBom',ref=>{
let query:firebase.firestore.query=ref;
query=query.where('orderPartLC','=',this.searchValue.toLowerCase());
返回查询;
}).valueChanges();
如果使用AngularFire2,您可以尝试:
//fireStore是AngularFire2注入的AngularFireStore的实例
let collection=fireStore.collection(“我的收藏名称”);
let options:GetOptions={source:“server”}
collection.ref.get(选项)。然后(结果=>{
//results包含一个名为docs的数组属性,该属性包含集合的文档。
});
将.valueChanges()
更改为.snapshotChanges()
,然后可以应用过滤器。请参见下面的示例。
我不喜欢更改默认行为(默认配置)我看到这是一种理想的行为,最好的做法是尽快向用户显示数据,即使您刷新两次屏幕
我认为在我们没有选择的情况下,从缓存===false进行过滤并不是一种不好的做法。(在我的情况下,我在收到第一个请求后会执行更多请求,因此由于承诺和其他异步“任务”缓存/服务器顺序完全丢失)
看
getChats(用户:用户){
返回此.afs.collection(“chats”,
ref=>ref.where('participantsId','array contains',user.id)
.snapshotChanges()
.pipe(过滤器(c=>c.payload.doc.metadata.fromCache===false))。
.pipe(映射(//可能希望在此处解析对象))
}
getChats(user : User) {
return this.afs.collection<Chat>("chats",
ref => ref.where('participantsId', 'array-contains', user.id)
.snapshotChanges()
.pipe(filter(c=> c.payload.doc.metadata.fromCache === false)).
.pipe(map(//probaly want to parse your object here))
}