title: Firebase: Cloud Functions, How to Cache a Firestore Document Snapshot
body: <p>I have a Firebase Cloud Function that I <a href="https://firebase.google.com/docs/functions/callable" rel="nofollow noreferrer">call directly from my app</a>. This cloud function fetches a collection of Firestore documents, iterating over each, then returns a result.</p>
  
  <p>My question is, would it be best to keep the result of that fetch/get in memory (on the node server), refreshed with <code>.onSnapshot</code>? It seems this would improve performance as my cloud function would not have to wait for the Firestore response (it would already have the collection in memory). How would I do this? Simple as populating a global variable? How to do <code>.onSnaphot</code> realtime listener with cloud functions?</p>