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 -4
View File
@@ -3,11 +3,12 @@
import { renderRepoCard } from "../src/cards/repo.js";
import { guardAccess } from "../src/common/access.js";
import {
CACHE_TTL,
resolveCacheSeconds,
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { CONSTANTS, parseBoolean, renderError } from "../src/common/utils.js";
import { parseBoolean, renderError } from "../src/common/utils.js";
import { fetchRepo } from "../src/fetchers/repo.js";
import { isLocaleAvailable } from "../src/translations.js";
@@ -67,9 +68,9 @@ export default async (req, res) => {
const repoData = await fetchRepo(username, repo);
const cacheSeconds = resolveCacheSeconds({
requested: parseInt(cache_seconds, 10),
def: CONSTANTS.PIN_CARD_CACHE_SECONDS,
min: CONSTANTS.ONE_DAY,
max: CONSTANTS.TEN_DAY,
def: CACHE_TTL.PIN_CARD.DEFAULT,
min: CACHE_TTL.PIN_CARD.MIN,
max: CACHE_TTL.PIN_CARD.MAX,
});
setCacheHeaders(res, cacheSeconds);