refactor: reorganize cache TTL constants (#4550)

* refactor: reorganize cache TTL constants

* Update tests/wakatime.test.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ophelia Goldstein
2025-10-09 03:41:02 +03:00
committed by GitHub
co-authored by Copilot Alexandr
parent 3c22841a82
commit 0afa6c4e78
13 changed files with 158 additions and 103 deletions
+5 -9
View File
@@ -3,16 +3,12 @@
import { renderStatsCard } from "../src/cards/stats.js";
import { guardAccess } from "../src/common/access.js";
import {
CACHE_TTL,
resolveCacheSeconds,
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import {
CONSTANTS,
parseArray,
parseBoolean,
renderError,
} from "../src/common/utils.js";
import { parseArray, parseBoolean, renderError } from "../src/common/utils.js";
import { fetchStats } from "../src/fetchers/stats.js";
import { isLocaleAvailable } from "../src/translations.js";
@@ -94,9 +90,9 @@ export default async (req, res) => {
);
const cacheSeconds = resolveCacheSeconds({
requested: parseInt(cache_seconds, 10),
def: CONSTANTS.CARD_CACHE_SECONDS,
min: CONSTANTS.TWELVE_HOURS,
max: CONSTANTS.TWO_DAY,
def: CACHE_TTL.STATS_CARD.DEFAULT,
min: CACHE_TTL.STATS_CARD.MIN,
max: CACHE_TTL.STATS_CARD.MAX,
});
setCacheHeaders(res, cacheSeconds);