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>
This commit is contained in:
Alexandr Garbuzov
2025-10-06 23:32:47 +03:00
committed by GitHub
co-authored by Alexandr
parent fde13639aa
commit ade7d53653
6 changed files with 60 additions and 60 deletions
+23
View File
@@ -0,0 +1,23 @@
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 };