I have an MVC 3 c# website running which pulls records from a webservice. As the dataset it gets from the webservice becomes bigger and bigger, I'm searching for a way that creating the cache of it isn't triggered by the first user to visit the site while there is no current cache, but on a daily schedule (like a cron job, scheduled task or something).
How should I do this? Do I need some sort of trigger library like Quartz.net ? (I'd rather use a simpler solution)
What I have in my controller now is:
private List<DataSummary> GetSummaries()
{
//get summaries from cache if available
List<DataSummary> summaries = (List<DataSummary>)HttpContext.Cache["SummariesCache"];
if (summaries == null)
{
//cache empty, retrieve values
summaries = _webservice.GetSummaries();
//cache it
HttpContext.Cache.Add("SummariesCache", summaries, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
return summaries;
}
Edit
using CacheItemRemovedCallback
causes time-out errors