title: Unable to make an object immutable
body: <p>I want to make a call to a server but if and only if the data (remoteIdKey in this case) is outdated. Here is how I'm doing it:</p>
  
  <pre><code>object remoteCaller {
  
   def getRemoteKeyId = {
  
     // do we need to get the data from the server?
     if (currentTime - lastCallTime &gt;= 1000) {
        remoteId = makeRemoteCall
        lastCallTime = currentTime
      }
  
      remoteId
    }
  
    private var remoteId = 0
    private def currentTime = //....
    private var lastCallTime = //....
    private def makeRemoteCall = { //remote call to the server to get the remote Id key} 
  }
  </code></pre>
  
  <p>The problem is that I mutate the state of <code>remoteCaller</code> and, therefore use <code>var</code> instead of <code>val</code>. And I also want use object instead of class to insure there it will be only instance of it.</p>
  
  <p>How can I make remoteCaller immutable or how do I do it the functional style (without mutation)?</p>