强制ember存储跳过缓存并从API调用中获取数据

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

我试图理解当我使用findAll时,如何强制ember store进行另一个api调用而不是从缓存中获取记录。我知道如果已经加载了记录,那么ember会返回缓存数据,除非要求跳过它。在进行一些研究(博客,文档和堆栈溢出)时,人们建议使用reload:true标志与findAll,但它不适合我。当我重新加载时:true flag然后store仍然从缓存中返回数据。

如果我错过任何东西,那么请帮忙。

我有以下代码:

fetchStudentData() {
   this.get('store').findAll('student').then((response) => {
         return response.data;
   });
}

此功能与按钮绑定,因此单击时我需要重新启动API调用。我更换了商店电话使用:

this.get('store').findAll('student', { reload: true }).then((response) => {
         return response.data;
   });

但这也没有帮助,因为它仍然在商店缓存中返回旧记录。

ember.js ember-data
1个回答
0
投票

我不熟悉您遇到的问题,但如果您根本不关心缓存,可以这样做:

async myMethod() {
  this.store.unloadAll('student');
  let students = await this.store.findAll('student');
}

令我困惑的是你的查询是你在你的response.data中做then,我知道data是原始json有效载荷的属性,但所有返回值的store方法返回模型。所以,你将获得学生实例而不是原始json(如果你想要原始的json(我建议不要这样),你可以使用fetch)。

© www.soinside.com 2019 - 2024. All rights reserved.