ASP.NET WebAPI OutputCache不起作用

时间:2016-08-21 08:49:00

标签: asp.net asp.net-web-api

我们有两个带OutputCaching的控制器,一个工作正常,第二个没有缓存......

工作控制器示例:

    [OutputCache(Duration = 1, VaryByParam = "idc,key")]
    public dynamic Get(string idc, string key)
    {

        string coins = idc;
        string size = key;
        try
        {
            Models.api.dicebets bets = new Models.api.dicebets();
            return bets.LastBets(coins, size);
        }
        catch
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid request");
        }
    }

具有非工作OutpuCache的类似控制器的示例:

    [OutputCache(Duration = 3)]
    public dynamic Get()
    {
        try
        {
            Models.api.dicebets bets = new Models.api.dicebets();
            return bets.HighRolls();
        }
        catch
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid request");
        }
    }

我已经尝试过所有OutputCache设置的组合,如:

[OutputCache(Duration = 3, VaryByParam = "None")]
[OutputCache(Duration = 3, VaryByParam = "*")]
[OutputCache(Duration = 3, VaryByParam = "")]

似乎没有用......

1 个答案:

答案 0 :(得分:0)

我们使用第三方缓存解决方案解决了这个问题:Strathweb.CacheOutput