From 2ea818591ec7d317f878a1646880bacec0eb5347 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 30 May 2021 17:55:11 +0530 Subject: [PATCH] cache control --- Cross.toml | 7 +++++-- src/main.rs | 2 +- src/static_assets/static_files.rs | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cross.toml b/Cross.toml index 412dc0b5..b09028d9 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,2 +1,5 @@ -[target.aarch64-unknown-linux-musl] -image = "realaravinth/cross:aarch64-unknown-linux-musl-postgres" +[build.env] +passthrough = [ + "RUST_BACKTRACE", + "RUST_LOG", +] diff --git a/src/main.rs b/src/main.rs index 01b061c2..4e8a5951 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,7 +86,7 @@ pub static PKG_NAME: &str = env!("CARGO_PKG_NAME"); pub static PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); pub static PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE"); -pub const CACHE_AGE: u32 = 365 * 24 * 3600; +pub const CACHE_AGE: u32 = 604800; #[cfg(not(tarpaulin_include))] #[actix_web::main] diff --git a/src/static_assets/static_files.rs b/src/static_assets/static_files.rs index 423b05e7..a93f2128 100644 --- a/src/static_assets/static_files.rs +++ b/src/static_assets/static_files.rs @@ -37,9 +37,12 @@ fn handle_assets(path: &str) -> HttpResponse { }; HttpResponse::Ok() - .set(header::CacheControl(vec![header::CacheDirective::MaxAge( - CACHE_AGE, - )])) + .set(header::CacheControl( + vec![ + header::CacheDirective::Public, + header::CacheDirective::Extension("immutable".into(), None), + header::CacheDirective::MaxAge(CACHE_AGE) + ])) .content_type(from_path(path).first_or_octet_stream().as_ref()) .body(body) } @@ -67,9 +70,12 @@ fn handle_favicons(path: &str) -> HttpResponse { }; HttpResponse::Ok() - .set(header::CacheControl(vec![header::CacheDirective::MaxAge( - CACHE_AGE, - )])) + .set(header::CacheControl( + vec![ + header::CacheDirective::Public, + header::CacheDirective::Extension("immutable".into(), None), + header::CacheDirective::MaxAge(CACHE_AGE) + ])) .content_type(from_path(path).first_or_octet_stream().as_ref()) .body(body) }