cache: Serve Range GET from disk when present
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:
@@ -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()).
|
||||
|
||||
Reference in New Issue
Block a user