title: Should I update my cache before or after I resolve my promise?
body: <p>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?</p>
  
  <p>When a promise is executed, <code>resolve</code> 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?</p>
  
  <p>This</p>
  
  <pre class="lang-js prettyprint-override"><code>new Promise((resolve, reject) =&gt; {
    let result = getThingFromApi();
    resolve(result);
    updateCache(result); // returns promise
  })
  </code></pre>
  
  <p>or this?</p>
  
  <pre class="lang-js prettyprint-override"><code>new Promise((resolve, reject) =&gt; {
    let result = getThingFromApi();
    updateCache(result); // returns promise
    resolve(result);
  })
  </code></pre>