I am displaying a table based on a query from a database. An ajax request is used to get the data from the table, serialise it into json and by using datatables JavaScript library on the front end, the data is updated.
I have a requirement to be able to then output that table to Excel. This needs to be in a very specific format for which I have written the class etc for in C# which correctly works. I also have the controller which will then pass back a filestream so the user can download the file.
My question is around caching the data from the database. I don't want to have to go back to the database and re run the query to then pass to my excel exporter the report, it should be stored in some way - the latest report that user has run.
There are two ways I can think of doing this:
1) client caching - store the latest report run by the user and then have the excel exporter use the latest report data from the cache.
2) send back the latest json response from the Ajax call and deserialise in the controller back into a report object.
Number one seems the most logical as two seems messy and prone to error. I'd like to know if this is the best solution and if not a suggestion on what method would be best.