title: Asynchronously reading and caching multiple files in nodejs
body: <p>I have an array which keeps URL of several files. For example:</p>
  
  <pre><code>var files = ['1.html', '2.html', '3.html'];
  </code></pre>
  
  <p>I need to read them asynchronously and save them in an object named cache (cache = {}).
  To do this I used the code:</p>
  
  <pre><code>for(var i = 0; i &lt; files.length; i++){
      require('fs').readFile(files[i], 'utf8', function (error,data) {
          cache[files[i]]=data;
      });
  }
  </code></pre>
  
  <p>In the end I have the result:</p>
  
  <pre><code>cache = { undefined : 'File 3 content' }
  </code></pre>
  
  <p>I do understand that the "readFile" acts after the loop is ended and it looses it's scope. Is there a way to fix this or another method to read files from an array and cache them?</p>