I am running into a weird situation where my model’s findAll store queries are always sending a request to the server even though the data for the specific model should already be cached. This is what I was trying:
this.store.findAll('devices/lock')
However, I always saw a network request to the server whenever I would navigate to the route that loads this model.
I then found information that findAll will try to do a background refresh of data after initially resolving it if it is already in store. This is not the behavior that I would like to achieve, so I changed my code to the following:
Unfortunately, this does not seem to work either, the requests are still always sent to the server when I navigate to this route. I have even try to add the following to my RESTAdapter:
shouldReloadRecord: function (store, ticketSnapshot) {
return false;
},
shouldBackgroundReloadRecord: function (store, snapshot) {
return false;
}
Does anybody know what the issue could be? Any help is greatly appreciated!
This sounds like a bug, and I vaguely recall running across this myself. I would open an issue if one already isn’t. For now, you can use the peek methods that @christophermilne mentioned.
@christophermilne unfortunately those two methods do not work for me, because I need to get the records once from the server. I could do a findAll and then if exists do a peekAll most likely, but it seems like there should be a better option.
@wecc that worked, thanks! Seems like a hacky solution for just wanting to do this for certain models.
@jasonmit I stepped through that method. It seems like the code should be a little different than it is.
Line 939:
if (adapter.shouldBackgroundReloadAll(this, snapshotArray)) {
promiseArray(_findAll(adapter, this, typeClass, sinceToken, options));
}
I feel like there should be a return in there and also the if statement should check if we are disabling background reload from the options. Is this inconsistent with what we expect (I feel like it is) and if so, where should I report this?