title: Is there a way to cache Socket.IO responses?
body: <p>For example, if I got this websocket:</p>
  
  <pre class="lang-js prettyprint-override"><code>let itemsArray = [];
  
  function fetchData() {
    itemsArray = await db.query(`SELECT * FROM Items`);
  }
  
  function emitData() {
    io.sockets.in("room_foo").emit("data", JSON.stringify(itemsArray));
  }
  
  setInterval(() =&gt; fetchData(), 2500);
  setInterval(() =&gt; emitData(), 5000);
  </code></pre>
  
  <p><em>basically this means the following: stream to all clients in <code>room_foo</code> the JSON array every 5 seconds and fetch the data every 2,5 seconds</em></p>
  
  <p>Now, here's the problem. When I connect to that WebSocket I have to wait 5 seconds until the next emit event occurs.</p>
  
  <p><strong>Is there a way I can cache the previous response for X <em>(5 in this specific case)</em> seconds, and emit that all the time in case someone connects, so they won't have such a delay?</strong>
  <em>Even if a new user connects (they don't have browser cache) - I mean server caching</em></p>