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

後端在以下情況使用
memoryYou need the fastest cache and can keep objects in RAM.
diskYou need cache capacity that survives process restarts.
tiered你希望熱物件使用記憶體,同時用磁碟提供更大容量。
storage-bin你預計高 churn,並希望磁碟分配有界。
encrypted diskYou 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

控制目的
lockCollapse concurrent misses so one request fills the cache.
range.sliceCache fixed byte slices for large files and resumable downloads.
peer_fill先讓一個 edge 從另一個 edge 填充,再存取 origin。
origin_protection在高壓力下限制併發 origin fills。
cache_purger以有界 batch 清理過期磁碟條目。

Use cache carefully

  • 攜帶 AuthorizationProxy-Authorization 的請求始終繞過共享快取查找和儲存。
  • 格式錯誤或衝突的回應 Cache-Control 指令將被拒絕,而不是回退到配置的 TTL;s-maxage 優先於 max-age
  • must-revalidateproxy-revalidates-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 狀態。首次以舊版加密快取根目錄啟動或輪替本機金鑰時,會在接收流量前主動清空該快取。

  • 將加密快取視為可丟棄的加速資料,而不是權威資料來源。
  • 為每個快取根提供持久性私有存儲,並且不在獨立根之間複製隨機數狀態。
  • 為升級或輪換金鑰後的首次快取預熱預留足夠的來源站容量。
繁體中文