DonutOutputCache ne nettoie pas le cache lors de l'utilisation de la variable
-
14-11-2019 - |
Question
J'ai un ActionResult que je veux qu'il soit mis en cache en fonction de l'identifiant
[DonutOutputCache(Duration = 3600, VaryByParam = "product_Id")]
public ActionResult ProductInfo(Guid product_Id)
{
System.Threading.Thread.Sleep(3000);
return PartialView(_repository.GetProductInfo(product_Id));
}
Ça marche bien.
Quand je veux supprimer le cache, j'utilise cette syntaxe
[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 (). Suppriter ne fonctionne pas lorsque je spécifie un paramètre.
Ça marche si j'utilise juste
cacheManager.RemoveItem("Common", "ProductInfo");
Qu'est-ce que je fais mal?
Pas de solution correcte
Autres conseils
J'ai trouvé la solution
Il semble que le paramètre ne puisse pas contenir de lettres majuscules. Il s'agit d'un bug connu qui sera corrigé.
Changer Product_id en Product_id et cela fonctionnera.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow