> For the complete documentation index, see [llms.txt](https://www.axisnow.io/zh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.axisnow.io/zh/docs/edge/policies/cache/configuration.md).

# 配置项

缓存控制五个配置项的取值与相互关系

五个配置项的取值与相互关系，组合方式见[配置场景](/zh/docs/edge/policies/cache/use-cases.md)。

## 边缘缓存 <a href="#edge-cache" id="edge-cache"></a>

* **可缓存**：按下面四项决定是否写入与如何命中。
* **绕过缓存**：不查缓存、直接回源、响应不写入。已有副本不删除，只是不再读取。绕过规则仍可配置浏览器缓存。

## 缓存时长 <a href="#ttl" id="ttl"></a>

三种模式决定源站缓存头、状态码规则和默认时长的取舍：

<table data-search="false"><thead><tr><th width="120">模式</th><th>取值顺序</th><th width="200">适合</th></tr></thead><tbody><tr><td>遵循源站</td><td>只看源站缓存头，源站未提供或指明不缓存时不缓存。状态码规则和默认时长不参与</td><td>源站缓存头可靠，只缓存源站明确允许的内容</td></tr><tr><td>源站优先</td><td>有源站缓存头按源站；没有时按状态码规则，都不命中用默认时长</td><td>多数站点</td></tr><tr><td>忽略源站</td><td>不看源站缓存头，按状态码规则，都不命中用默认时长。源站的 <code>no-store</code>、<code>private</code> 也不阻止缓存</td><td>源站缓存头不可控，或要强制缓存</td></tr></tbody></table>

源站缓存头的解读：`Cache-Control` 含 `no-cache`、`no-store`、`private` 或 `max-age=0` 为不缓存；`s-maxage` 优先于 `max-age`；只有 `Cache-Control` 而没有 `max-age` 时视为未提供。没有 `Cache-Control` 时看 `Expires`，已过期的 `Expires` 同样视为未提供，而不是不缓存。`Pragma` 不参与。源站返回 `Cache-Control: max-age=60, s-maxage=86400` 可以让边缘缓存一天而浏览器只缓存一分钟。

**状态码缓存时长**按响应状态码给出不同时长，从上到下取第一条命中。平台内置三条：302、303 缓存 1200 秒，404、410 缓存 60 秒，5xx 不缓存；自定义规则都不命中时这三条仍然生效，要改变它们就添加一条覆盖相同状态码的规则。

**默认时长**在源站未提供缓存头且状态码规则都不命中时使用。0 为不缓存；任何状态码只要算出的时长大于 0 都会缓存，包括重定向。源站优先和忽略源站模式下源站的改动要等时长到期才会体现，需要立即生效时用[清理](/zh/docs/edge/policies/cache/purge-and-warming.md)。

## 缓存 Key <a href="#cache-key" id="cache-key"></a>

Key 决定哪些请求共用一份副本。协议、域名、URI 路径、方法始终参与，http 与 https 是两份副本。另外三个维度可配置：

<table data-search="false"><thead><tr><th width="120">维度</th><th>选项</th></tr></thead><tbody><tr><td>查询参数</td><td>全部、无、只包含列出的、排除列出的。参数顺序不影响，<code>?a=1&#x26;b=2</code> 与 <code>?b=2&#x26;a=1</code> 是同一副本</td></tr><tr><td>Cookie</td><td>全部、无、只包含列出的、排除列出的</td></tr><tr><td>请求头</td><td>无、只包含列出的</td></tr></tbody></table>

预设对应的组合：

<table data-search="false"><thead><tr><th width="140">预设</th><th width="130">查询参数</th><th width="110">Cookie</th><th>请求头</th></tr></thead><tbody><tr><td>默认</td><td>全部</td><td>无</td><td>无</td></tr><tr><td>静态资源</td><td>无</td><td>无</td><td>无</td></tr><tr><td>带版本参数</td><td>包含 <code>v</code>、<code>ver</code></td><td>无</td><td>无</td></tr><tr><td>多语言</td><td>全部</td><td>无</td><td>包含 <code>Accept-Language</code></td></tr><tr><td>区分登录态</td><td>全部</td><td>全部</td><td>无</td></tr></tbody></table>

参与 Key 的维度越多副本越分散、命中率越低。`utm_*`、`fbclid` 这类统计参数和会话 ID、时间戳每次请求都不同，静态资源用排除或预设**静态资源**把它们排除在外；Cookie 选全部时每个用户各一份副本，等于不缓存，区分登录态时只包含登录 Cookie。参数名和 Cookie 名区分大小写，请求头名不区分。`Accept-Encoding` 不需要加入请求头，边缘已按压缩算法分别缓存。

## 缓存分片 <a href="#slice" id="slice"></a>

开启后大文件按设定大小切片，每片独立缓存，客户端的 Range 请求只回源取相应分片。源站必须支持 Range 请求，并对同一文件返回一致的 `ETag`；Safari 和 iOS 播放视频、拖动进度依赖 Range，视频路径要开启分片。分片越小首字节越快、回源次数越多；分片越大则相反。`.js`、`.css` 不分片。只有开启分片时 Range 才透传到源站：关闭分片、绕过缓存或没有规则命中的请求，边缘都会从头拉取完整响应后自行应答 Range。

## 浏览器缓存 <a href="#browser-cache" id="browser-cache"></a>

* **遵循源站**：不改动源站的 `Cache-Control` 和 `Expires`。
* **自定义**：去掉源站的这两个头，下发 `Cache-Control: max-age=<秒数>`。
* **不缓存**：去掉源站的这两个头，下发 `Cache-Control: no-cache`。

浏览器缓存只影响下发给客户端的头，不影响边缘是否缓存。下发到浏览器的副本无法从平台清除：会更新的内容（HTML、不带版本号的脚本和样式）给浏览器设短时长或不缓存，边缘设长时长，更新时清理边缘即可。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.axisnow.io/zh/docs/edge/policies/cache/configuration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
