为了提高性能,可以通过缓存来提供响应。 默认情况下,响应存储 2 分钟。
可以通过 HTTP 请求中的 Cache-Control
标头设置缓存选项。有关详细信息,请参阅此文。
API 支持标准的 max-age
、no-cache
和 no-store
指令。
max-age
指定缓存的响应保持有效状态的最大时间长度(以秒为单位)。no-cache
和no-store
会绕过响应缓存,始终查询下游服务。
例如,以下请求允许的最大缓存期限为 30 秒
POST https://api.loganalytics.azure.cn/v1/workspaces/{workspace-id}/query
Authorization: Bearer <access token>
Cache-Control: max-age=30
{
"query" : "Heartbeat | count"
}
如果从缓存返回响应,则 Age
标头指定响应的过期时间(以秒为单位)。
例如,以下响应在 13 秒后过期。
HTTP/1.1 200 OK
Age: 13
Content-Type: application/json; charset=utf-8
{
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "count_",
"type": "long"
}
],
"rows": [
[
1939908516
]
]
}
]
}