Question

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?

No correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top