# 缓存过滤

## 缓存过滤概述

在某些情况下，数据集的总大小可能会超过分配给Alluxio缓存的总磁盘空间。 为了解决这个问题，Alluxio提供了缓存过滤功能，使我们可以仅缓存热门数据。 通过配置缓存过滤，用户可以根据文件路径指定要缓存的特定文件。

## 配置

要启用缓存过滤功能，请在`alluxio-site.properties`文件中添加以下配置：

```properties
alluxio.user.client.cache.filter.enabled=true
alluxio.user.client.cache.filter.class=alluxio.client.file.cache.filter.RuleSetBasedCacheFilter
alluxio.user.client.cache.filter.type=RULE_SET
alluxio.user.client.cache.filter.config.file=${ALLUXIO_HOME}/conf/cache_filter.json
alluxio.user.client.cache.filter.config.check.interval=5min
```

* `alluxio.user.client.cache.filter.config.file` 用于指定设置过滤规则的JSON文件路径
* `alluxio.user.client.cache.filter.config.check.interval` 用于检查JSON文件的间隔

这两个属性允许在运行中的集群上动态更新过滤规则。

### 在JSON文件中设置过滤规则

Alluxio中有三种不同类型的过滤规则：

* Immutable（不可变）：假设UFS上的文件永远不会更改；这些文件被缓存且永不驱逐
* Skip Cache（跳过缓存）：假设UFS上的文件经常更改；这些文件从不缓存，总是从UFS读取
* Max Age（存活时间）：假设UFS上的文件将在指定时间间隔内更改；这些文件被缓存，但设置为在一定时间间隔后过期

下面是一个示例JSON文件，展示了如何设置规则。

```json
{
  "apiVersion": 1,
  "data": {
    "immutable": [".*/immutable_tables/.*"],
    "skipCache": [".*/skip_cache_tables/.*"],
    "maxAge": {".*/mutable_tables/.*":"10s"},
    "defaultType": "immutable"
  },
  "metadata": {
    "immutable": [".*/immutable_tables/.*"],
    "skipCache": [".*/skip_cache_tables/.*"],
    "maxAge": {".*/mutable_tables/.*":"10s"},
    "defaultType": "immutable"
  }
}
```

这个JSON文件有两个部分。一部分是**metadata**（元数据），另一部分是**data**（数据）。让我们以数据部分为例。

* `immutable`键设置了一个带有正则表达式模式`.*/immutable_tables/.*`的单例列表，因此这些文件将永不驱逐。
* `skipCache`键设置了一个带有正则表达式模式`.*/skip_cache_tables/.*`的单例列表，因此这些文件将永不缓存。
* `maxAge`键设置了一个单条目映射`{".*/mutable_tables/.*":"10s"}`。 匹配正则表达式模式`.*/mutable_tables/.*`的文件将被缓存，并在`10s`后过期。

**metadata**部分的设置方式相同，因此相同文件的元数据将具有相同的缓存行为。 这两种类型被分别定义，以允许每种类型具有不同的行为。

最后，我们可以为不匹配任何配置的正则表达式模式的文件设置默认类型。 在这个例子中，`defaultType`是`immutable`。


---

# 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/ai-3.2/feature/cache-filter.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.
