禁用Angular Firestore查询中的缓存

问题描述 投票:1回答:1

我正在运行firestore查询以获取数据,但查询先前从缓存的数据查询返回数据,然后在服务器的第二次传递中返回其他数据(之前未查询)。有没有办法可以禁用firestore查询的缓存,以便每次查询时请求都会转到DB。

this.parts$ = this.db.collection<OrderBom>('OrderBom', ref => {
      let query : firebase.firestore.Query = ref;
      query = query.where('orderPartLC', '==', this.searchValue.toLowerCase());
      return query;
    }).valueChanges();
google-cloud-firestore angularfire
1个回答
0
投票

如果使用AngularFire2,您可以尝试:

  1. 我在Internet上读到你可以禁用离线持久性 - 它可以缓存你的结果 - 而不是在AngularFireStoreModule上调用enablePersistence()。
  2. 我做了第一次但仍然没有成功,但先试试。我设法摆脱缓存结果是使用类DocumentReference中的get()方法。此方法接收GetOptions作为参数,您可以强制数据来自服务器。用法示例:

// fireStore is a instance of AngularFireStore injected by AngularFire2
    let collection = fireStore.collection<any>("my-collection-name");
    let options:GetOptions = {source:"server"}
    collection.ref.get(options).then(results=>{
    // results contains an array property called docs with collection's documents.
    });
© www.soinside.com 2019 - 2024. All rights reserved.