Files
github-stats-extended/src/common/cache.js
T
Alexandr GarbuzovandAlexandr ade7d53653 refactor: move cache seconds calculation logic into reusable function (#4532)
* refactor: move cache seconds calculation logic into reusable function

* dev

---------

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
2025-10-06 23:32:47 +03:00

24 lines
783 B
JavaScript

import { clampValue } from "./utils";
/**
* Resolves the cache seconds based on the requested, default, min, and max values.
*
* @param {Object} args The parameters object.
* @param {number} args.requested The requested cache seconds.
* @param {number} args.def The default cache seconds.
* @param {number} args.min The minimum cache seconds.
* @param {number} args.max The maximum cache seconds.
* @returns {number} The resolved cache seconds.
*/
const resolveCacheSeconds = ({ requested, def, min, max }) => {
let cacheSeconds = clampValue(parseInt(requested || def, 10), min, max);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;
return cacheSeconds;
};
export { resolveCacheSeconds };