ASP.NET Core 2.2响应缓存在浏览器上不起作用

时间:2019-01-30 00:40:15

标签: c# asp.net-core asp.net-core-webapi asp.net-core-2.2

响应缓存在Postman中运行良好,但缓存在其他浏览器中不起作用,并且浏览器中的“缓存控制”是“ public,max-age = 60”。 每次刷新浏览器时,都会调用action方法。 我的Api代码:

[HttpGet]
    [ResponseCache(Duration =60)]

    public IActionResult GetAllCustomer()
        {           
        Request.HttpContext.Response.Headers.Add("X-Total-Custumer", _h_Plus_SportsContext.Customer.Count().ToString());

        return new ObjectResult(_customerService.GetAllCustomer())
        {
            StatusCode = (int)HttpStatusCode.OK
        };
    }

1 个答案:

答案 0 :(得分:0)

您应该提供更多的上下文,但是默认情况下,Chrome和其他可能的浏览器会发送+----+--------+------------+ | ID | AMOUNT | DEPLETIONS | +----+--------+------------+ | 1 | 3 | 0 | | 2 | 2 | 0 | | 3 | 1 | 6 | | 4 | 4 | 0 | | 5 | 7 | 11 | | 6 | 1 | 0 | | 7 | 2 | 0 | | 8 | 10 | 13 | | 9 | 3 | 0 | | 10 | 4 | 7 | | 11 | 2 | 0 | | 12 | 4 | 6 | | 13 | 8 | 8 | +----+--------+------------+ 标头,其值为0(即使Chrome Dev Tools的“禁用缓存”未选中,也会发生这种情况):

Cache control 0

一种解决方法是将链接指向要测试的链接,或使用“ here”所示的“返回”按钮。

相关问题