瀏覽代碼

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

将首页的缓存控制头从禁止缓存改为允许客户端在 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]]
 [[package]]
 name = "swb-sys-monitor"
 name = "swb-sys-monitor"
-version = "0.1.3"
+version = "0.2.0"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "clap",
  "clap",

+ 1 - 1
Cargo.toml

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

+ 3 - 11
src/server.rs

@@ -63,20 +63,12 @@ impl StatusServer {
             (&Method::GET, "/") => {
             (&Method::GET, "/") => {
                 match Self::serve_html(cache).await {
                 match Self::serve_html(cache).await {
                     Ok(mut response) => {
                     Ok(mut response) => {
-                        // 添加缓存控制头,减少客户端重复请求
+                        // 添加缓存控制头,允许客户端在 10 秒内使用缓存
+                        // 与 HTML meta refresh 和服务器缓存 TTL 保持一致,减少服务器负载
                         response.headers_mut().insert(
                         response.headers_mut().insert(
                             "Cache-Control",
                             "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)
                         Ok(response)
                     }
                     }
                     Err(_) => Ok(Self::serve_error(
                     Err(_) => Ok(Self::serve_error(