mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-09-20 21:50:11 +08:00
fix(审计修复): 缓存穿透TTL共享 + 预刷新网络/超时 + 最大化/APM优先设计注释
- 新增 cacheBusterInterceptor.ts:createCacheBusterInterceptor(ttl=5min) 带 TTL 复用戳, 解决同会话频繁击穿缓存(B1)并将 App.vue/storeConfig 两处重复逻辑合并为共享工厂(I3) - storeConfig.ts: priorityConfigAxios 改用共享拦截器;HYBRID_DEFAULT_PRIORITY 加注释 明确「主推 APM 是既定产品方向」(B2,非缺陷) - App.vue: axiosInstance 改用共享拦截器(带 TTL) - index.ts: 预刷新 startSourcePreRefreshOnce 加 net.isOnline() 检查 + 60s 超时兜底, 避免离线/卡死触发 pkexec 弹窗困惑(I1);createWindow 恢复逻辑加注释明确 「最大化后恢复重置为默认尺寸是有意设计,非缺陷」(I2) - vue-tsc + eslint 通过
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { InternalAxiosRequestConfig } from "axios";
|
||||
|
||||
/**
|
||||
* 缓存穿透拦截器工厂:为所有 .json GET 请求追加 ?_t=${timestamp} 版本戳,
|
||||
* 穿透 CDN/浏览器缓存,确保新应用上架后能立即被搜到(解决"上架后搜不到")。
|
||||
*
|
||||
* 为避免同一次会话内每次请求都生成新戳导致缓存完全失效(频繁重复请求、浪费带宽),
|
||||
* 引入 TTL:在 ttlMs 窗口内复用同一时间戳;超过窗口才刷新。
|
||||
* 默认 5 分钟,兼顾"及时感知新数据"与"不过度击穿缓存"。
|
||||
*
|
||||
* 注意:这是有意为之的缓存击穿策略(非缺陷),用于解决商店目录强缓存导致的更新延迟。
|
||||
*/
|
||||
export function createCacheBusterInterceptor(ttlMs = 5 * 60 * 1000) {
|
||||
let cachedTimestamp: number | null = null;
|
||||
|
||||
return (config: InternalAxiosRequestConfig): InternalAxiosRequestConfig => {
|
||||
if (
|
||||
config.method?.toLowerCase() === "get" &&
|
||||
typeof config.url === "string"
|
||||
) {
|
||||
const reqPath = config.url.split("?")[0];
|
||||
if (reqPath.endsWith(".json")) {
|
||||
const now = Date.now();
|
||||
if (cachedTimestamp === null || now - cachedTimestamp > ttlMs) {
|
||||
cachedTimestamp = now;
|
||||
}
|
||||
const sep = config.url.includes("?") ? "&" : "?";
|
||||
config.url = `${config.url}${sep}_t=${cachedTimestamp}`;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user