ソースを参照

【新增,服务端】调整首页缓存策略以减少服务器负载

将首页的缓存控制头从禁止缓存改为允许客户端在 10 秒内使用缓存,
与 HTML meta refresh 和服务器缓存 TTL 保持一致,从而减少服务器负载。
同时移除了不必要的 Pragma 和 Expires 头部设置。
PJ568 1 年間 前
親
コミット
de6fc05940
3 ファイル変更、5 行追加、13 行削除
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 3 11
      src/server.rs

+ 1 - 1
Cargo.lock

@@ -942,7 +942,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
 
 [[package]]
 name = "swb-sys-monitor"
-version = "0.1.3"
+version = "0.2.0"
 dependencies = [
  "anyhow",
  "clap",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "swb-sys-monitor"
-version = "0.1.3"
+version = "0.2.0"
 authors = ["PJ568 <[email protected]>"]
 edition = "2024"
 description = "为嵌入式设备高并发监控场景设计的极简网页资源占用显示系统"

+ 3 - 11
src/server.rs

@@ -63,20 +63,12 @@ impl StatusServer {
             (&Method::GET, "/") => {
                 match Self::serve_html(cache).await {
                     Ok(mut response) => {
-                        // 添加缓存控制头,减少客户端重复请求
+                        // 添加缓存控制头,允许客户端在 10 秒内使用缓存
+                        // 与 HTML meta refresh 和服务器缓存 TTL 保持一致,减少服务器负载
                         response.headers_mut().insert(
                             "Cache-Control",
-                            hyper::header::HeaderValue::from_static(
-                                "no-cache, no-store, must-revalidate",
-                            ),
+                            hyper::header::HeaderValue::from_static("public, max-age=10"),
                         );
-                        response.headers_mut().insert(
-                            "Pragma",
-                            hyper::header::HeaderValue::from_static("no-cache"),
-                        );
-                        response
-                            .headers_mut()
-                            .insert("Expires", hyper::header::HeaderValue::from_static("0"));
                         Ok(response)
                     }
                     Err(_) => Ok(Self::serve_error(