title: Django: how to cache a function
body: <p>I have a web application that runs python in the back-end. When my page loads, a django function is called which runs a SQL query and that query takes about 15-20 seconds to run and return the response. And that happens every time the page loads and it would be very annoying for the user to wait 15-20 secs every time the page refreshes. </p>
  
  <p>So I wanted to know if there is a way to cache the response from the query and store it somewhere in the browser when the page loads the first time. And whenever, the page refreshes afterwards, instead of running the query again, I would just get the data from browser's cache and so the page would load quicker. </p>
  
  <p>This is the function that runs when the page loads</p>
  
  <pre><code>def populateDropdown(request):
      database = cx_Oracle.connect('username', 'password', 'host')
      cur = database.cursor()
      cur.execute("select distinct(item) from MY_TABLE")
      dropList = list(cur)
      dropList = simplejson.dumps({"dropList": dropList})
      return HttpResponse(dropList, content_type="application/json")
  </code></pre>
  
  <p>I can't seem to find an example on how to do this. I looked up Django's documentation on caching but it shows how to cache entire page not a specific function. It would be great if you can provide a simple example or link to a tutorial. Thanks :)</p>