Refactor to serve all responses from cached files on disk
- StoreOutput now returns output hash for immediate retrieval - Cache misses now serve from disk file after storing (same as hits) - Log served_bytes from actual io.Copy result (avoids stat calls) - Remove ContentLength field usage for cache hits (stream from file) - Fix tests to properly check all return values
This commit is contained in:
@@ -124,26 +124,26 @@ func (s *Handlers) HandleImage() http.HandlerFunc {
|
||||
w.Header().Set("ETag", resp.ETag)
|
||||
}
|
||||
|
||||
// Log cache status and timing
|
||||
// Stream the response
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
servedBytes, err := io.Copy(w, resp.Content)
|
||||
if err != nil {
|
||||
s.log.Error("failed to write response",
|
||||
"error", err,
|
||||
)
|
||||
}
|
||||
|
||||
// Log cache status and timing after serving
|
||||
duration := time.Since(startTime)
|
||||
s.log.Info("image served",
|
||||
"cache_key", cacheKey,
|
||||
"cache_status", resp.CacheStatus,
|
||||
"duration_ms", duration.Milliseconds(),
|
||||
"format", req.Format,
|
||||
"served_bytes", resp.ContentLength,
|
||||
"served_bytes", servedBytes,
|
||||
"fetched_bytes", resp.FetchedBytes,
|
||||
)
|
||||
|
||||
// Stream the response
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
_, err = io.Copy(w, resp.Content)
|
||||
if err != nil {
|
||||
s.log.Error("failed to write response",
|
||||
"error", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user