title: Transferring a (fairly) large amount of data across a single page load
body: <p>I have an application that generates an array of statistics based on a greyhounds racing history. This array is then used to generate a table which is then output to the browser. I am currently working on creating a function that will generate an excel download based on these statistics. However, this excel download will only be available after the original processing has been completed. Let me explain.</p>
  
  <ol>
  <li>The user clicks on a race name</li>
  <li>The data for that race is then processed and displayed in a table.</li>
  <li>Underneath the table is a link for an excel download.</li>
  </ol>
  
  <p>However, this is where I get stuck. The excel download exists within another method within the same controller like so...</p>
  
  <pre><code>function view($race_id) {
      //Process race data and place in $stats
      //Output table &amp; excel link
  }
  
  function view_excel($race_id) {
      //Process race data &lt;- I don't want it to have to process all over again!
      //Output excel sheet
  }
  </code></pre>
  
  <p>As you can see, the data has already been processed in the "view" method so it seems like a massive waste of resources having it processed again in the "view_excel" method.</p>
  
  <p>Therefore, I need a method of transferring <strong>$stats</strong> over to the excel method when the link is clicked to prevent it having to be reproduced. The only methods I can think of are as follows.</p>
  
  <ul>
  <li>Transferring $stats over to the excel method using a session flash
  <ul>
  <li><em>The variable may end up being too big for a session variable. Also, if for some reason the excel method is refreshed, the variable will be lost.</em></li>
  </ul></li>
  <li>Transferring $stats over to the excel method using an ordinary session variable
  <ul>
  <li><em>As above, the variable may end up being too big for a session variable. This has the benefit that it wont be lost on a page refresh but I'm not sure how I would go about destroying old session variables, especially if the user it processing alot of races in a short period of time.</em></li>
  </ul></li>
  <li>Storing $stats in a database and retrieving it in the excel method
  <ul>
  <li><em>This seems like the most viable method. However, it seems like a lot of effort to just transfer one variable across. Also, I would have to implement some sort of cron job to remove old database entries.</em></li>
  </ul></li>
  </ul>
  
  <p>An example of <strong>$stats</strong>:</p>
  
  <pre><code>Array
  (
      [1] =&gt; Array
          (
              [fcalc7] =&gt; 
              [avgcalc7] =&gt; 
              [avgcalc3] =&gt; 86.15
              [sumpos7] =&gt; 
              [sumpos3] =&gt; 9
              [sumfin7] =&gt; 
              [sumfin3] =&gt; 8
              [total_wins] =&gt; 0
              [percent_wins] =&gt; 0
              [total_processed] =&gt; 4
              [total_races] =&gt; 5
          )
  
      [2] =&gt; Array
          (
              [fcalc7] =&gt; 28.58
              [avgcalc7] =&gt; 16.41
              [avgcalc3] =&gt; 28.70
              [sumpos7] =&gt; 18
              [sumpos3] =&gt; 5
              [sumfin7] =&gt; 23
              [sumfin3] =&gt; 7
              [total_wins] =&gt; 0
              [percent_wins] =&gt; 0
              [total_processed] =&gt; 7
              [total_races] =&gt; 46
          )
  
      [3] =&gt; Array
          (
              [fcalc7] =&gt; 28.47
              [avgcalc7] =&gt; 16.42
              [avgcalc3] =&gt; 28.78
              [sumpos7] =&gt; 28
              [sumpos3] =&gt; 11
              [sumfin7] =&gt; 21
              [sumfin3] =&gt; 10
              [total_wins] =&gt; 0
              [percent_wins] =&gt; 0
              [total_processed] =&gt; 7
              [total_races] =&gt; 63
          )
  )
  </code></pre>
  
  <p>Would be great to hear your ideas.</p>
  
  <p>Dan</p>