# 缓存管理

Alluxio 充当计算层与持久化存储之间的缓存层。理解如何管理这个缓存——什么数据进入、什么数据保留、什么数据被移除——是实现稳定高性能工作负载的关键。

## 我想做什么？

| 目标               | 工具                     | 指南                                                             |
| ---------------- | ---------------------- | -------------------------------------------------------------- |
| 在作业运行前预热数据集      | `job load`             | [加载数据](/ee-ai-cn/cache/loading-data-into-the-cache.md)         |
| 防止关键模型被驱逐        | Cache Priority（缓存固定）   | [缓存策略 → 固定](/ee-ai-cn/cache/managing-data-in-the-cache.md)     |
| 自动过期过时或临时数据      | TTL                    | [缓存策略 → TTL](/ee-ai-cn/cache/managing-data-in-the-cache.md)    |
| 控制缓存数据的新鲜度       | Cache Filter（`maxAge`） | [缓存策略 → Filter](/ee-ai-cn/cache/managing-data-in-the-cache.md) |
| 按团队或目录限制缓存用量     | Quota                  | [缓存策略 → Quota](/ee-ai-cn/cache/managing-data-in-the-cache.md)  |
| 在作业完成或版本更新后移除数据集 | `job free`             | [缓存驱逐 → 手动](/ee-ai-cn/cache/removing-data-from-the-cache.md)   |

## 缓存生命周期工作原理

### 1. 数据进入缓存

两种路径：

* **被动缓存（read-through）**：缓存未命中时，Worker 从 UFS 拉取数据并自动缓存。无需任何配置——但第一次读取会较慢。
* **主动预加载**：使用 `job load` 在任何读取发生前将数据推入缓存，消除定时作业和模型推理的冷启动延迟。

[缓存加载 →](/ee-ai-cn/cache/loading-data-into-the-cache.md)

### 2. 策略控制哪些数据保留及保留多久

数据缓存后，四种机制管控其行为：

* **Cache Priority（缓存固定）** — 将数据标记为 `HIGH` 优先级，使 LRU 在有低优先级数据可驱逐时不会优先驱逐它
* **TTL** — 设置硬过期时间：数据超过生命周期后被驱逐，与访问频率无关
* **Cache Filter** — 控制准入：immutable、skip cache 或 max-age 重新验证
* **Quota** — 限制目录树可消耗的缓存空间上限

[缓存策略 →](/ee-ai-cn/cache/managing-data-in-the-cache.md)

### 3. 数据离开缓存

三种方式：

* **自动驱逐**：LRU（默认）、LFU 或 FIFO 在 Worker 空间不足时移除数据
* **TTL 过期**：后台扫描移除生命周期已到期的数据
* **手动移除**：`job free` 显式清除一个路径——用于废弃某个模型版本或按需释放空间时

[缓存驱逐 →](/ee-ai-cn/cache/removing-data-from-the-cache.md)

## 策略指南

### LLM / ML 模型推理

*示例：微调模型、基础模型权重、Embedding 索引。*

**目标**：零冷启动，关键模型永不被驱逐。

1. 推理前预加载：`job load --path s3://models/llama3/ --submit --verify`
2. 固定防止 LRU 驱逐：`alluxio priority add --path s3://models/llama3/ --priority high`
3. 模型更新时：`job free --path s3://models/llama3-v1/ --submit` → 重新加载 v2

### 周期性更新数据

*示例：每日 ETL 输出、再训练数据集。*

**目标**：数据新鲜且命中率高。

* 使用 `maxAge` filter（如 `1d`），使 Alluxio 在过期后下次访问时重新验证
* 上游更新后运行 `job load --skip-if-exists` 预热新版本

### 临时或检查点数据

*示例：训练检查点、临时查询结果。*

**目标**：避免短生命周期数据填满缓存。

* 使用 `skipCache` filter 完全绕过缓存，或
* 设置较短 TTL（如 `1h`）+ `LOW` 优先级，使其优先被驱逐

### 合规 / 敏感数据

*示例：PII 日志、GDPR 限定目录。*

**目标**：严格限制数据在缓存中的存活时长。

* 设置符合合规要求的 TTL 时间窗口（如 `90d`）
* 处理完成后立即执行 `job free`


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.alluxio.io/ee-ai-cn/cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
