feat: add analytics data cache toggle

This commit is contained in:
eoao
2026-05-10 13:12:22 +08:00
parent 80242d5c24
commit 44bbf9c3da
5 changed files with 19 additions and 3 deletions

View File

@@ -9,6 +9,10 @@ import { toUtc } from '../utils/date-uitil';
const analysisService = {
async echarts(c, params) {
if (!this.analysisCacheEnabled(c)) {
return await this.queryEcharts(c, params);
}
const cacheKey = this.echartsCacheKey(params);
const cache = await c.env.kv.get(cacheKey, { type: 'json' });
@@ -27,6 +31,10 @@ const analysisService = {
},
async refreshEchartsCache(c) {
if (!this.analysisCacheEnabled(c)) {
return;
}
const { keys } = await c.env.kv.list({ prefix: kvConst.ANALYSIS_ECHARTS });
await Promise.all(keys.map(key => this.refreshEchartsCacheByKey(c, key.name)));
@@ -117,6 +125,10 @@ const analysisService = {
return {
timeZone: decodeURIComponent(cacheKey.replace(kvConst.ANALYSIS_ECHARTS, ''))
};
},
analysisCacheEnabled(c) {
return c.env.analysis_cache === true || c.env.analysis_cache === 'true';
}
}