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-revalidate, proxy-revalidate และ s-maxage ห้ามมิให้นำกลับมาใช้ใหม่หลังจากที่ความสดหมดอายุ
  • Keep cache keys bounded and predictable.
  • ใช้ storage-bin root หนึ่งรายการต่อ Fluxheim process ที่กำลังทำงาน ownership ใช้ advisory filesystem lock ดังนั้น shared multi-writer root จะไม่ปลอดภัยหากไม่มี external locking ที่ผ่านการตรวจสอบ
  • ใช้ TTL แบบล้างข้อมูลหรือแบบสั้นเมื่อเนื้อหามีการเปลี่ยนแปลงบ่อยครั้ง
  • Bypass on cookies, preview headers, and unsafe query strings.

บันทึกการอัพเกรดแคชที่เข้ารหัส

Fluxheim 1.7.12 ย้ายออบเจ็กต์แคชของดิสก์ที่เข้ารหัสไปยังข้อมูลที่ผูกกับรูทและคีย์ดัชนีด้วยสถานะ nonce ที่คงทน การเริ่มต้นครั้งแรกกับรูทที่เข้ารหัสเก่า และการหมุนคีย์ในเครื่องทุกครั้ง ตั้งใจจะล้างแคชนั้นก่อนให้บริการการรับส่งข้อมูล

  • ให้ถือว่าแคชที่เข้ารหัสเป็นข้อมูลเร่งความเร็วที่ลบทิ้งได้ ไม่ใช่แหล่งข้อมูลหลัก
  • ให้พื้นที่เก็บข้อมูลส่วนตัวถาวรของแคชรูททุกตัว และอย่าคัดลอกสถานะ nonce ระหว่างรูทที่เป็นอิสระ
  • เตรียมความจุของเซิร์ฟเวอร์ต้นทางให้เพียงพอสำหรับการอุ่นแคชครั้งแรกหลังอัปเกรดหรือหมุนเวียนคีย์
ไทย