【发布时间】:2018-01-09 21:28:21
【问题描述】:
我有一个 ASP.NET Webforms 应用程序。为了获得更好的性能,我以编程方式在 Masterpage 的 Page-Load 中设置了 Outputcache:
protected void Page_Load(object sender, EventArgs e)
{
// [...] do stuff [...]
if (!Page.IsPostBack)
{
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetValidUntilExpires(true); // ignore Cache-Control Header from Request
Response.Cache.SetSlidingExpiration(false);
Response.Cache.VaryByParams["*"] = true;
Response.Cache.SetExpires(somedateinthefuture); // plus 5 Days from now
Response.AddFileDependency(pathtoafile); // a file which will be overwritten when cache should be fully cleared (this works)
}
}
因此,对于每个唯一的 Url,都会缓存 HTML。这工作得很好。
问题:
- 许多条目会在 1 或 3 分钟后从缓存中随机删除,尽管它应该会持续很多天
- 一些条目会保留 24 小时或更长时间,但也会在持续时间之前被删除
我检查了什么:
- 依赖文件尚未更新
- IIS 应用程序或应用程序池尚未重新启动或回收
- Pool 内存未达到最大值
- 在测试网站上的输出缓存比在生产网站上的停留时间长得多
- 单个项目会过期,而不是整个缓存
- 按“STRG+F5”重新加载被调用站点
- IIS 7.5、ASP.NET 4.6.1
什么会导致单个缓存项被删除。也许机器人?但是这不应该被 SetValidUntilExpires(true) 阻止吗?
【问题讨论】: