4

我有一个 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");

我究竟做错了什么?

4

1 回答 1

3

我找到了解决方案

看来参数不能包含大写字母。这是一个已知的错误,将被修复。

将 product_Id 更改为 product_id 即可。

于 2012-01-28T10:03:10.127 回答