Reputation: 257
I am trying to understand how can I force ember store to make another api call instead of fetching records from cache when I use findAll. I know if records are already loaded then ember returns cached data unless asked to skip it. On doing some study (blogs, documentation and stack overflow), people has suggested to use reload: true flag with findAll but its not working for me. When I do a reload:true flag then store still returns me data from the cache.
If I am missing anything, then please help.
Code I have:
fetchStudentData() {
this.get('store').findAll('student').then((response) => {
return response.data;
});
}
This function is tied to a button so on clicking I need to re-initiate the API call. I replaced the store call to use:
this.get('store').findAll('student', { reload: true }).then((response) => {
return response.data;
});
But this also didnt help as it still returned me old records in the store cache.
Upvotes: 2
Views: 947
Reputation: 65173
I'm not familiar with the issue you are having, but if you don't care about your cache at all, you could do this:
async myMethod() {
this.store.unloadAll('student');
let students = await this.store.findAll('student');
}
Something that puzzled me about your query is that you're doing response.data
inside your then
, I know data
is an attribute on the raw json payload, but all the store
methods that return values return Models. So, you'll get student instances back instead of raw json (if you want raw json (I recommend against this), you can just use fetch
).
Upvotes: 1