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 GarbuzovandAlexandr authored and martin-mfg committed 2025-10-25 13:29:37 +02:00
1 parent c3e537a4c4
commit 06ac549cfe
6 files changed
+60 -54

No files matched your search

+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 };