Инвалидировать кеш используя VaryByCustom
Я хочу сделать кеш недействительным, используя атрибут VaryByCustom. Следующий код используется для настройки кэша.
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (!string.IsNullOrWhiteSpace(arg))
{
if (context.User.Identity.Name != null)
{
return context.User.Identity.Name;
}
}
return base.GetVaryByCustomString(context, arg);
}
1 ответ
Вы используете это так:
Убедитесь, что вы украсили свое действие атрибутом:
[OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom =
"YourStringThatIsArgParamInYourGlobalAsaxMethod")]
public ActionResult MyActionOnTheController(string myParam)
{
}