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您期望高流失率並希望有限的磁碟分配。
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在使用原點之前,讓一邊從另一邊填滿。
origin_protection限制高壓期間並發的原點填充。
cache_purger批次清理陳舊的磁碟條目。

Use cache carefully

  • 帶有 Authorization 或者 Proxy-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 管理,所以未有經驗證 external locking 嘅共享 multi-writer root 並唔安全。
  • 當內容經常變更時,請使用清除或短 TTL。
  • Bypass on cookies, preview headers, and unsafe query strings.

加密緩存升級筆記

Fluxheim 1.7.12 對加密磁碟快取物件使用綁定快取根目錄嘅資料金鑰同索引金鑰,並持久保存 nonce 狀態。首次用舊版加密快取根目錄啟動或者輪替本機金鑰時,會喺接收流量之前主動清空快取。

  • 將加密快取當成可以棄置嘅加速資料,而唔係權威資料來源。
  • 畀每個緩存根持久嘅私人儲存空間,同埋唔好喺獨立根之間複製 nonce 狀態。
  • 為升級或者輪換金鑰之後第一次快取預熱,預留足夠嘅源站容量。
粵語