Edge Cache Strategy Design
openflare-edge (components/edge/src/proxy/cache.rs) integrates TinyUFO memory and optional disk storage via pingap-cache, gating HTTP response caching with both node-level performance policies and route-level rules. For telemetry reporting fields (cache_status), see OpenFlare Edge Reporting Protocol & Observability Data Model.
1. Enablement Gates and Scope
Caching activates only when all of the following conditions hold:
- Node performance policy (
cache_enabled): Controls whetherEdgeCachestorage is enabled on the edge node. - Route toggle (
route.cache_enabled): Enables caching per proxy route. - Feature exclusions:
components/edge/src/proxy/mod.rsbypasses HTTP caching on routes with site authentication (site_auth_ttl_hours != 0) or HTTP Basic auth enabled. Pages static deployments are served directly bycomponents/edge/src/pages/withETagand byte-range handling outsideEdgeCache.
2. Two-Stage Caching Decisions (components/edge/src/proxy/cache.rs)
2.1 Request Eligibility (Stage A)
EdgeCache::enable skips cache lookup and storage unless every check passes:
- Method check: Only
GETrequests are eligible;HEAD,POST, and other methods bypass cache. - Sensitive/special header bypass: Requests carrying
Authorization,Upgrade(WebSocket), orRangeheaders skip caching directly. - Route policy (
cache_policy) matching:
cache_policy | Behavior | Default | Legacy Compatibility |
|---|---|---|---|
static | Matches built-in static extensions case-insensitively (excluding html, htm, json) | Yes | — |
all | Caches any path/extension passing method & header checks (requires accurate origin Cache-Control) | No | Legacy url normalizes to all |
suffix | Matches custom extensions configured in cache_rules | No | Requires at least one extension |
path_prefix | Matches URI path prefixes in cache_rules | No | Prefixes start with / |
path_exact | Matches exact URI paths in cache_rules | No | Paths start with / |
Built-in static extensions:
css js mjs map
ico cur gif jpg jpeg png webp avif svg svgz
ttf otf woff woff2 eot
mp3 mp4 webm ogg flac
wasm pdf
zip 7z gz tar[!NOTE] Regular visitor cookies alone do not bypass
staticasset caching; session safety is enforced on the response side by blockingSet-Cookieandprivate/no-storeresponses.
2.2 Response Cacheability and Default Edge TTL (Stage B)
For eligible requests, EdgeCache::response validates origin headers before admitting objects into TinyUFO:
- Non-cacheable responses: Any response with
Set-Cookie,Vary: *, or non-shareableCache-Control(private,no-store,no-cache) is forwarded to the client without storing in cache. - Key isolation &
Vary: Primary keys hash{snapshot_digest}|{max_object_bytes}|{scheme}|{host}|{request_uri}so raw URLs and query strings never leak into logs or filenames, whileVaryresponse headers build secondary variance keys. - Request coalescing & object limits: Global
CacheLock(60s base timeout tuned viacache_lock_wait_timeout/cache_max_lock_retries) coalesces concurrent fills. Maximum cached object size respectscache_max_object_mibbounded by available store capacity (and 25% of node memory budget in disk mode). - Default status TTLs: When the origin omits explicit freshness headers (
Cache-Control/Expires),EdgeCacheapplies status-based defaults alongside optionalstale_updating/stale_on_error(60s stale window):
| Status Code | Default Edge TTL |
|---|---|
200, 206, 301 | 7200s (120m) |
302, 303 | 1200s (20m) |
404, 410 | 180s (3m) |
3. Code Map
| Area | Path |
|---|---|
| Key generation, eligibility, TinyUFO backend & disk sweep | components/edge/src/proxy/cache.rs, components/edge/src/proxy/mod.rs |
| Performance policy settings & startup validation | components/edge/src/runtime/performance.rs |
Route cache policy validation & url → all normalization | internal/apps/openflare/proxy_route/helpers.go |
| Snapshot compiler defaults | internal/openflare/edgeconfig/, internal/apps/openflare/config_version/snapshot.go |
| Console cache configuration UI | frontend/app/(main)/proxy-routes/detail/components/cache-section.tsx |