【发布时间】:2017-11-03 04:43:49
【问题描述】:
目前我有以下操作,它将告诉客户端将响应缓存 1200 秒:
[ResponseCache(Location = ResponseCacheLocation.Client, Duration = 1200)]
[HttpGet("universities")]
public IActionResult GetAllUniversities(string location)
{
if (/*location not found*/)
return BadRequest();
...
return Ok(universities);
}
在响应头中,当它返回 Ok (200) 时,我收到了以下值:
Cache-Control: private, max-age=1200
正如预期的那样完美。
当我将错误的位置传递给 API 并且 API 返回 BadRequest (400) 时,它也会返回与上述相同的 Cache-Control 值。
我的问题是,这是最佳做法吗?还是应该返回 no-cache, no-store 而不是 400?如果应该,我如何在 200 时返回 private, max-age=1200 并在 .NET Core 中仅针对此特定操作返回 no-cache, no-store?
【问题讨论】:
标签: c# asp.net-web-api asp.net-core cache-control