cache: Serve Range GET from disk when present
CI / vulncheck (pull_request) Successful in 15s
CI / check-and-test (pull_request) Successful in 41s

Steam clients lean on Range requests. Hit/miss looked fine while downloads
still felt cold when a Range miss returned the full upstream body as 200.

Add range_cache / range_upstream metrics. HIT path already sliced 206 from
the cached full object; count range_cache there. On MISS, keep stripping
Range for the upstream fetch (full object still cached) but serve the
client's requested slice as 206 and count range_upstream.

Tests in steamcache/range_test.go cover Range HIT (local, no upstream),
Range MISS (206 + full object cached), and /metrics emission.
This commit is contained in:
2026-09-07 16:32:36 +00:00
parent c43bfba568
commit ac2d36f1ad
5 changed files with 456 additions and 7 deletions
+7
View File
@@ -262,6 +262,13 @@ func (sc *SteamCache) streamCachedResponse(w http.ResponseWriter, r *http.Reques
// Send the range data
_, _ = w.Write(rangeData) // client write error ignored (disconnect during range body send is not actionable)
// Range served from cache: count the range-specific metric and the range
// bytes actually written (handleCacheHit skips full-blob byte counting for
// Range requests so these are not double-counted).
sc.metrics.IncrementRangeCache()
sc.metrics.AddBytesServed(int64(len(rangeData)))
sc.metrics.AddBytesSaved(int64(len(rangeData)))
logger.Logger.Info().
Str("cache_key", cacheKey).
Str("url", r.URL.String()).