Reputation: 177
I have a very simple object within an ASP.NET MVC based website.
Model:
public class Visualisation
{
public string name { get; set; }
public string[] relationships { get; set; }
}
It is used to build up a name and an array of relationships of the data held within my website and then displayed via a D3JS graphic.
Controller:
public ActionResult Visualisations()
{
List<Visualisation> VisualList = new List<Visualisation>();
/*
A whole lot of database hits, foreach loops, heaps of CPU and db time
*/
return View(VisualList);
}
The problem is that the building of this page (hundreds of users with thousands of records with dozens of pieces of data being collated for this report) takes up to 30 seconds and is only going to get worse, but the data itself doesn't really need to be updated all that often.
Is there a way to essentially store the VisualList object somewhere after it is made the first time and if less than 24 hours has passed, return that object to the view, if more than 24 hours, rebuild it and pass the new copy.
Also, in a perfect world, the report would just be built automatically every 24 hours, so the user never has to wait the 30+ seconds for it to load.
Upvotes: 0
Views: 1043
Reputation: 557
Beside cache and trying to optimize business/db logic. How about Lazy< T > instead of List< T >
Check out those links:
https://sankarsan.wordpress.com/2009/10/04/laziness-in-c-4-0-lazyt/
Upvotes: 0
Reputation: 569
The easiest option for you is cache it, and give it a 24h life time, check this.
If the data is the same for every request, you can use the [OutputCache]
from mvc that will cache out the View output, not the data. check this.
Upvotes: 4