perf: add ETag and server-side caching for thumbnail proxy
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 49s

Add ETag header to API thumbnail responses for 304 Not Modified support.
Forward If-None-Match/ETag through the Next.js proxy route handler and
add next.revalidate for 24h server-side fetch caching to reduce
SSR-to-API round trips on the libraries page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 06:52:47 +01:00
parent 691b6b22ab
commit ee65c6263a
2 changed files with 31 additions and 7 deletions

View File

@@ -631,12 +631,17 @@ pub async fn get_thumbnail(
crate::pages::render_book_page_1(&state, book_id, 300, 80).await?
};
let etag_value = format!("\"{}_{:x}\"", book_id, data.len());
let mut headers = HeaderMap::new();
headers.insert(header::CONTENT_TYPE, HeaderValue::from_static(content_type));
headers.insert(
header::CACHE_CONTROL,
HeaderValue::from_static("public, max-age=31536000, immutable"),
);
if let Ok(v) = HeaderValue::from_str(&etag_value) {
headers.insert(header::ETAG, v);
}
Ok((StatusCode::OK, headers, Body::from(data)))
}