In my application, I get information from an API and cache it. If the cache misses and I end up retrieving the data to store it, when should I update the cache?
When a promise is executed, resolve
does not stop the execution of the rest of the function. I want to return the information as soon as possible, so if I resolve the promise first, and then update the cache, would I actually reap any performance benefits? Or am I setting myself up for race conditions or something like that down the road?
This
new Promise((resolve, reject) => {
let result = getThingFromApi();
resolve(result);
updateCache(result); // returns promise
})
or this?
new Promise((resolve, reject) => {
let result = getThingFromApi();
updateCache(result); // returns promise
resolve(result);
})