> ## Documentation Index
> Fetch the complete documentation index at: https://ppio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 缓存

> 查阅 PPIO Agent 沙箱 Template 缓存的使用说明，了解模板构建中的缓存相关行为，为准备和维护可复用运行环境提供参考。

Template 构建会缓存此前已完成的层(layer),这样重复构建时无需重新执行每条指令,从而加快迭代速度。仅在需要强制全新构建时才跳过缓存——跳过缓存会使构建明显变慢。

缓存默认开启,无需任何配置。当你需要跳过缓存并强制重建时,SDK 和 CLI 提供三个层级的控制:

| 作用范围 | 效果 | 用法 |
| - | - | - |
| 整个构建 | 忽略所有缓存,从零开始重建整个 Template | JS: `ppio.template.build(t, name, { skipCache: true })`  Python: `ppio.template.build(t, name, skip_cache=True)` |
| 从某一层起 | 强制**该指令及其后所有层**重新构建;若正好放在 `from*`(FROM)指令上,则整个 Template 的缓存都会失效 | JS: `.skipCache()`  Python: `.skip_cache()` |
| CLI | 构建过程中忽略缓存 | `ppio template build --no-cache` |

> [!WARNING]
>
> **重要:** 链式方法 `skipCache()` / `skip_cache()` 并非只跳过单条指令——它们会作用于调用点之后的**所有后续层**。调用位置越靠前,失效的缓存范围就越大。

**示例:** 在定义中跳过缓存并强制完整重建(两种方式可以组合使用)。

```python Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()

template = (
    ppio.template.new().from_python_image("3.12")
    .skip_cache()  # 从这里开始的所有层都不使用缓存
    .run_cmd("pip install -U pip")
)

build = ppio.template.build(
    template,
    "my-template-no-cache",
    skip_cache=True,  # 忽略整个 Template 的缓存
)
```

```javascript JavaScript & TypeScript theme={null}
import { PPIO } from 'ppio-sandbox'

const ppio = new PPIO()

const template = ppio.template.new().fromPythonImage('3.12')
  .skipCache() // 从这里开始的所有层都不使用缓存
  .runCmd('pip install -U pip')

const build = await ppio.template.build(template, 'my-template-no-cache', {
  skipCache: true, // 忽略整个 Template 的缓存
})
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.