我正在考虑使用后台工作程序在Application_Start上预加载一堆页面,例如:
private BackgroundWorker _cacheWarmup;
protected void Application_Start()
{
_cacheWarmup.DoWork += cacheWarmup_DoWork;
_cacheWarmup.RunWorkerAsync();
}
void cacheWarmup_DoWork(object sender, DoWorkEventArgs e)
{
CacheWarmup.CachePages();
}
public class CacheWarmup
{
public static void CachePages()
{
var webClient = new WebClient();
var pagesToCache = GetEarlyCachePages();
foreach (var page in pagesToCache)
{
webClient.DownloadString(page);
}
}
}
这样页面将使用[OutputCache]属性缓存服务器端。这看起来有点难看,我找不到任何真正做过类似事情的人。所以,我想我的问题是: