mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-21 14:10:11 +08:00
fix(cache): 列表/分类请求禁用客户端缓存,根治新应用上架后搜不到
- C1: 主进程 onBeforeSendHeaders 对 .json 数据请求注入 Cache-Control: no-cache + Pragma - C2: 渲染端 axiosInstance 与 priorityConfigAxios 对 .json GET 追加 ?_t 时间戳版本戳,穿透 CDN 边缘缓存 - 按去除 query 的 pathname 判断 .json,兼容 C2 自身追加的 ?_t,避免 C1/C2 交互失效 - 根因: nginx 无 Cache-Control 头 -> Chromium 启发式缓存(≈(now-LastModified)/10) 复用陈旧副本,重启仍命中旧 JSON,仅删 Cache 目录才生效
This commit is contained in:
@@ -12,6 +12,20 @@ const priorityConfigAxios = axios.create({
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
// C2:priority-config.json 走独立 axios 实例(不经过 axiosInstance),
|
||||
// 同样追加 ?_t 版本戳以穿透 CDN 边缘缓存,与 C1 的 no-cache 注入互为兜底。
|
||||
priorityConfigAxios.interceptors.request.use((config) => {
|
||||
if (config.method?.toLowerCase() === "get" && typeof config.url === "string") {
|
||||
// 按去除 query 的 pathname 判断,兼容 C2 自身追加的 ?_t= 及任何既有 query
|
||||
const reqPath = config.url.split("?")[0];
|
||||
if (reqPath.endsWith(".json")) {
|
||||
const sep = config.url.includes("?") ? "&" : "?";
|
||||
config.url = `${config.url}${sep}_t=${Date.now()}`;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export const APM_STORE_STATS_BASE_URL: string =
|
||||
import.meta.env.VITE_APM_STORE_STATS_BASE_URL || "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user