🚧 wip: messing with cache parameters

main
_ 2022-01-09 00:22:16 +00:00
parent b642142332
commit c47ab6d282
1 changed files with 6 additions and 4 deletions

View File

@ -198,11 +198,12 @@ async fn serve_file (
// - no-cache - Clients and the relay can store this, but should revalidate // - no-cache - Clients and the relay can store this, but should revalidate
// with the origin server (us) because only we can check if the file // with the origin server (us) because only we can check if the file
// changed on disk. // changed on disk.
// - max-age=0 - The file might change at any point during or after the // - max-age=5 - Caches can keep the file for 5 seconds. This is just enough
// request, so for proper invalidation, the client should immediately // to let a cache like Nginx or Varnish on a relay soak up some of a
// consider it stale. // slashdotting for us, but not so much that a low-traffic site would
// suffer from seeing stale data.
response.header ("cache-control".to_string (), b"no-cache,max-age=0".to_vec ()); response.header ("cache-control".to_string (), b"no-cache,max-age=5".to_vec ());
if let Some (etag) = input.actual_etag { if let Some (etag) = input.actual_etag {
response.header ("etag".to_string (), etag); response.header ("etag".to_string (), etag);
}; };
@ -246,6 +247,7 @@ fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput
if let (Some (if_none_match), Some (actual_etag)) = (&input.if_none_match, &input.actual_etag) if let (Some (if_none_match), Some (actual_etag)) = (&input.if_none_match, &input.actual_etag)
{ {
if actual_etag == if_none_match { if actual_etag == if_none_match {
info! ("Not Modified");
return ServeFileOutput { return ServeFileOutput {
status_code: StatusCode::NotModified, status_code: StatusCode::NotModified,
should_send_body: false, should_send_body: false,