我有一个 ActionResult 我希望它基于 id 被缓存
[DonutOutputCache(Duration = 3600, VaryByParam = "product_Id")]
public ActionResult ProductInfo(Guid product_Id)
{
System.Threading.Thread.Sleep(3000);
return PartialView(_repository.GetProductInfo(product_Id));
}
它运作良好。
当我想删除缓存时,我使用这种语法
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveDetails(DetailsModel model)
{
try
{
// save action here, then remove cache
var cacheManager = new OutputCacheManager();
cacheManager.RemoveItem("Common", "ProductInfo", new { product_Id = model.Product_Id });
return Json(new { hasError = false }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { hasError = true, message = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
当我指定参数时,OutputCacheManager().RemoveItem 不起作用。
如果我只使用它就可以了
cacheManager.RemoveItem("Common", "ProductInfo");
我究竟做错了什么?