I can't remove cache when i use VaryByParam

Jan 27, 2012 at 2:25 PM


I am using MVC 3

I have an ActionResult which i want it to be cached based on the product_Id parameter. It is working good.

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

When i try to remove the cache, however, it is not working.

This is my approach:

public ActionResult SaveDetails(DetailsModel model)
        // 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);

If i specify a parameter to RemoveItem method, it is not working.

If i just call the function without parameter, it works.

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

How can i fix this problem?

Thank you

Jan 28, 2012 at 12:02 PM

Currently there is a problem with parameters names that contains uppercase letters. This is a known bug which will be fixed.

Change product_Id to product_id and it will work.