title: Should I cache firebase refs?
body: <p>I'm developing a web app backed with firebase realtime database.</p>
  
  <p>The app's frontend is quite complex and there are several methods that write data to the db. I have several utils that look like this:</p>
  
  <pre><code>var utils = {
      setSomething: function(id, item) {
          var myRef = firebase.database().ref('my/path');
          myRef.set(item).then(something);
      }
  }
  </code></pre>
  
  <p>The question here is: is it okay to create a new Ref inside the method (and thereby, creating a new ref with each call) or should I "cache" the ref somewhere else (just like we cache jquery objects).</p>
  
  <p>I could do something like this first:</p>
  
  <pre><code>var cachedRefs = {
      myRef: firebase.database().ref('my/path'),
      yourRef: firebase.database().ref('your/path'),
      herRef: firebase.database().ref('her/path')
  }
  </code></pre>
  
  <p>And then the former method could be rewritten as:</p>
  
  <pre><code>var utils = {
      setSomething: function(id, item) {
          cachedRefs.myRef.set(item).then(something);
      }
  }
  </code></pre>
  
  <p>Is there any <strong>performance</strong> gain besides having less code repetition?</p>