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 | คุณคาดว่าจะมีการเปลี่ยนแปลงสูงและต้องการการจัดสรรดิสก์แบบมีขอบเขต |
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 | ให้ขอบด้านหนึ่งเติมจากอีกขอบหนึ่งก่อนใช้จุดเริ่มต้น |
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 ระหว่างรูทที่เป็นอิสระ
- เตรียมความจุของเซิร์ฟเวอร์ต้นทางให้เพียงพอสำหรับการอุ่นแคชครั้งแรกหลังอัปเกรดหรือหมุนเวียนคีย์