Cache
Use cache when Fluxheim sits in front of an origin and repeated responses should be served faster.
Proxy cache example
[cache]
enabled = true
default_ttl_secs = 300
max_object_bytes = "32MiB"
status_header = "X-Cache-Status"
[cache.memory]
enabled = true
max_size_bytes = "256MiB"
[cache.disk]
enabled = true
path = "/var/cache/fluxheim/site"
max_size_bytes = "10GiB"
Cache backends
| 后端 | 在以下情况使用 |
|---|---|
memory | You need the fastest cache and can keep objects in RAM. |
disk | You need cache capacity that survives process restarts. |
tiered | 你希望热对象使用内存,同时用磁盘提供更大容量。 |
storage-bin | 你预计高 churn,并希望磁盘分配有界。 |
encrypted disk | You need cache-at-rest protection for disk objects. |
Route cache policy
[[vhosts.routes]]
name = "assets"
path_prefix = "/assets/"
action = "proxy"
[vhosts.routes.proxy]
upstreams = ["127.0.0.1:3000"]
[vhosts.routes.cache]
enabled = true
status_ttls = { "200" = 3600, "404" = 60 }
content_types = ["text/css", "application/javascript", "image/*"]
extensions = ["css", "js", "png", "webp", "svg"]
include_query = false
stale_while_revalidate_secs = 30
stale_if_error_secs = 120
Advanced cache controls
| 控制 | 目的 |
|---|---|
lock | Collapse concurrent misses so one request fills the cache. |
range.slice | Cache fixed byte slices for large files and resumable downloads. |
peer_fill | 先让一个 edge 从另一个 edge 填充,再访问 origin。 |
origin_protection | 在高压力下限制并发 origin fills。 |
cache_purger | 以有界 batch 清理过期磁盘条目。 |
Use cache carefully
- 携带
Authorization或Proxy-Authorization的请求始终绕过共享缓存查找和存储。 - 格式错误或冲突的响应
Cache-Control指令将被拒绝,而不是回退到配置的 TTL;s-maxage优先于max-age。 must-revalidate、proxy-revalidate、s-maxage禁止保鲜期满后重复使用。- Keep cache keys bounded and predictable.
- 每个运行中的 Fluxheim process 使用一个独立的 storage-bin root;所有权依赖 advisory filesystem lock,因此在未验证外部 locking 的情况下,共享 multi-writer root 并不安全。
- 内容频繁变化时使用 purge 或较短 TTL。
- Bypass on cookies, preview headers, and unsafe query strings.
加密缓存升级说明
Fluxheim 1.7.12 为加密磁盘缓存对象使用绑定到缓存根目录的数据密钥和索引密钥,并持久保存 nonce 状态。首次使用旧版加密缓存根目录启动或轮换本地密钥时,会在接收流量前主动清空该缓存。
- 将加密缓存视为可丢弃的加速数据,而不是权威数据源。
- 为每个缓存根提供持久私有存储,并且不在独立根之间复制随机数状态。
- 为升级或轮换密钥后的首次缓存预热预留足够的源站容量。