The guide says about cached records:
One downside to returning a cached record is you may find the state of the data has changed since it was first loaded into the store’s identity map. In order to prevent this stale data from being a problem for long, Ember Data will automatically make a request in the background each time a cached record is returned from the store. When the new data comes in, the record is updated, and if there have been changes to the record since the initial render, the template is re-rendered with the new information.
Okay, on the surface, that’s simple enough to understand. But I’m not completely certain of the implementation. Let’s say I have a simple model foo
that has one property text
. And in my route I have this:
model() {
return this.store.findRecord('foo', 123).then((foo) => {
console.debug('foo:', foo.get('text'));
return foo;
});
}
And in the route I have:
{{my-controller foo=model}}
So two things here:
- Does this mean the
console.debug()
will actually run twice, once when the cached record is returned immediately, and then once again when the updated record is returned? - Will
my-component
first receive the cached record, and then receive the updated record (ie,didReceiveAttrs()
runs twice)?