簡體   English   中英

使用VaryByCustom使緩存無效

[英]Invalidate Cache using 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);
}

你是這樣使用它的:

確保使用屬性修飾您的操作:

 [OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom = 
  "YourStringThatIsArgParamInYourGlobalAsaxMethod")]
  public ActionResult MyActionOnTheController(string myParam)
 {
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM