我一直试图弄清楚为什么 outputCache 在以下设置中没有被清除。
几乎我检查过的每个链接以清除 outputCacheItem 都说只调用 RemoveOutputCacheItem(string) 方法。但是我发现情况并非如此。我在调试器中得到该方法一次,它转到 ClearCacheName(),运行删除。之后我再也没有点击该方法,告诉我缓存被卡住了,因此结果集永远为空。
[OutputCache(Duration = int.MaxValue, Location = OutputCacheLocation.Server)]
public JsonResult GetNames()
{
if (SomeResultSet != null)
{
var results =
SomeResultSet
.Where(x => x.LookupName != null)
.OrderBy(x => x.LookupName)
.Select(x => new
{
value = x.LookupName,
label = x.LookupName
}).Distinct();
return new JsonResult() {Data = results, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}
ClearCacheNames();
return null;
}
private void ClearCacheNames()
{
// OutputCacheAttribute.ChildActionCache = new MemoryCache(new Guid().ToString());
Response.RemoveOutputCacheItem(Url.Action("GetNames","Search",null));
}