title: How to cache the data pulled from BigQuery in Django?
body: <p>I have a webapp that pulls data from BigQuery into my Django views, which then will be passed as a context to the frontend templates. However, this data pulling process will occur initially when I open the web, and will occur again everytime I refresh the page. Is there a way I can cache the data I have pulled?</p>
  <p>My <code>views.py</code> code looks similarly to this:</p>
  <pre class="lang-py prettyprint-override"><code>def index(request):
      client = bigquery.Client()
      dataset_id = &quot;project-id.dataset-id&quot;
      tables = client.list_tables(dataset_id)
      tables_list = [table.table_id for table in tables]
  
      data_list = []
      for table_id in tables_list:
           query_string = f&quot;&quot;&quot;
                SELECT *
                FROM `project-id.dataset-id.{table_id}`
           &quot;&quot;&quot;
      
           query_job = (
                client.query(query_string)
                .result()
           )
  
           records = [dict(row) for row in query_job]
           data_list.extend(records)
  
      df = pd.DataFrame(data_list)
      ...
      # Data manipulation syntax here using pandas dataframe
      ...
      data_json = df.to_json(orient=&quot;records&quot;)
  
      context = {'data_json': data_json}
  
      return render(request, 'template_name', context)
  </code></pre>
  <p>I passed the data as a JSON to the context because I'm passing it to a React frontend.</p>