gpt4 book ai didi

asp.net-mvc - 使用变量时 DonutOutputCache 不会清除缓存

转载 作者:行者123 更新时间:2023-12-02 03:43:00 25 4
gpt4 key购买 nike

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

我做错了什么?

最佳答案

我找到了解决办法

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

将product_Id更改为product_id即可。

关于asp.net-mvc - 使用变量时 DonutOutputCache 不会清除缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9021289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com