title: Caching expensive computation in elixir
body: <p>I have an web application in elixir that looks like this</p>
  
  <pre><code>defmodule Test do
    use Plug.Router
  
    plug :match
    plug :dispatch
  
    def expensiveComputation() do
       // performs an expensive computation and
       // returns a list
    end
  
    get "/randomElement" do
      randomElement = expensiveComputation() |&gt; Enum.random
      send_resp(conn, 200, randomElement)
    end
  
  end
  </code></pre>
  
  <p>Whenever I issue a <code>GET</code> request to <code>/randomElement</code>, <code>expensiveComputation</code> gets called. The <code>expensiveComputation</code> function takes a long time to run but returns the same thing every time it is called. What is the simplest way to cache the result so that it gets run only once on startup?</p>