This commit is contained in:
xiaojunnuo
2026-05-20 16:00:14 +08:00
parent fb5b00d73f
commit 1e7b057946
4 changed files with 12 additions and 5 deletions
@@ -37,7 +37,7 @@
</div>
<div class="flex-between mt-5">
<div class="flex-o"><fs-icon icon="ant-design:check-outlined" class="color-green mr-5" /> 监控站点数</div>
<suite-value :model-value="detail.monitorCount.max" :used="detail.monitorCount.used" unit="" />
<suite-value :model-value="detail.monitorCount.max" :used="detail.monitorCount.used" unit="" />
</div>
</div>
</template>
@@ -1,6 +1,11 @@
export function shouldSetDefaultNoCache(path: string, cacheControl?: string) {
if(path === '/' || path === '/index.html' ){
//首页不管怎样都不要缓存
return true;
}
if (cacheControl) {
return false;
}
return path === '/' || path === '/index.html' || path.startsWith('/api');
// api也不要缓存,如果他本身有设置缓存除外
return path.startsWith('/api');
}
@@ -13,7 +13,9 @@ describe("shouldSetDefaultNoCache", () => {
});
it("keeps explicit cache headers from file responses", () => {
assert.equal(shouldSetDefaultNoCache("/api/basic/file/download", "public,max-age=259200"), false);
assert.equal(shouldSetDefaultNoCache("/", "public,max-age=259200"), true);
assert.equal(shouldSetDefaultNoCache("/index.html", "public,max-age=259200"), true);
assert.equal(shouldSetDefaultNoCache("/api/basic/file/download", "public,max-age=259200"), false);
});
it("ignores non-html and non-api paths", () => {
@@ -126,7 +126,7 @@ export class MainConfiguration {
await next();
const path = ctx.path;
// 如果是首页则强制设置为不缓存
if (path === '/' || path === '/index.html' || shouldSetDefaultNoCache(path, ctx.response.get('Cache-Control')) ) {
if (shouldSetDefaultNoCache(path, ctx.response.get('Cache-Control')) ) {
ctx.response.set('Cache-Control', 'public,max-age=0');
}
});
@@ -138,6 +138,6 @@ export class MainConfiguration {
logger.info('当前环境:', this.app.getEnv()); // prod
// throw new Error("address family not supported")
}
}