문제

I have an ActionResult which i want it to be cached based on the id

[DonutOutputCache(Duration = 3600, VaryByParam = "product_Id")]
public ActionResult ProductInfo(Guid product_Id)
{
    System.Threading.Thread.Sleep(3000);
    return PartialView(_repository.GetProductInfo(product_Id));
}

It is working good.

When i want to remove the cache, i use this syntax

[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 doesn't work when i specify a parameter.

It works if i just use

cacheManager.RemoveItem("Common", "ProductInfo");

What am i doing wrong?

올바른 솔루션이 없습니다

다른 팁

I found the solution

it seems that the parameter can't contain uppercase letters. This is a known bug which will be fixed.

Change product_Id to product_id and it will work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top