代码之家  ›  专栏  ›  技术社区  ›  Frode Lillerud

如何对多个参数使用VaryByParam?

  •  98
  • Frode Lillerud  · 技术社区  · 16 年前

    在ASP.NET我使用的MVC2 OutputCache 以及 VaryByParam

    [OutputCache(Duration=30, VaryByParam = "customerId"]
    public ActionResult Index(int customerId)
    {
    //I've got this one under control, since it only has one parameter
    }
    
    [OutputCache(Duration=30, VaryByParam = "customerId"]
    public ActionResult Index(int customerId, int languageId)
    {
    //What is the correct syntax for VaryByParam now that I have a second parameter?
    }
    

    如何让它使用这两个参数来缓存页面?我要输入两次添加属性吗?或者写“customerId,languageId”作为值??

    2 回复  |  直到 5 年前
        1
  •  204
  •   Ian Kemp    5 年前

    VaryByParam 是以下内容之一:

    • * (星号),因 全部的 动作方法的参数。
    • 文本字符串 none (不区分大小写),因 不 动作方法的参数。
    • 一个字符串,其中包含以分号分隔的参数名称,这些参数是您希望根据这些名称进行更改的。

    在您的情况下,您需要第一个选项:

    [OutputCache(Duration = 30, VaryByParam = "*")]
    public ActionResult Index(int customerId, int languageId)
    {
    }
    

    [OutputCache(Duration = 30, VaryByParam = "customerId;languageId")] // foo is omitted
    public ActionResult Index(int customerId, int languageId, int foo)
    {
    }
    

    Reference.

        2
  •  1
  •   Aryan Firouzian pooja gautam    7 年前

    你也可以使用 * 包括所有参数

     [OutputCache(Duration =9234556,VaryByParam = "*")]