Add CACHE_ENABLED toggle for IUAM cache
All checks were successful
CI / release (push) Successful in 1m15s

This commit is contained in:
estebanthi
2026-01-23 17:22:18 +01:00
parent 44660055af
commit 85d380d8e4
2 changed files with 6 additions and 2 deletions

View File

@@ -63,6 +63,7 @@ npm start # Production mode
| `authToken` | `null` | API authentication token |
| `browserLimit` | `20` | Max concurrent browsers |
| `timeOut` | `60000` | Global timeout (ms) |
| `CACHE_ENABLED` | `true` | Enable IUAM response cache |
## 📡 API Endpoints

View File

@@ -13,6 +13,9 @@ global.timeOut = Number(process.env.timeOut) || 60000
const CACHE_DIR = path.join(__dirname, "cache")
const CACHE_FILE = path.join(CACHE_DIR, "cache.json")
const CACHE_TTL = 5 * 60 * 1000
const CACHE_ENABLED = process.env.CACHE_ENABLED
? !["0", "false", "no"].includes(process.env.CACHE_ENABLED.toLowerCase())
: true
function loadCache() {
if (!fs.existsSync(CACHE_FILE)) return {}
@@ -109,7 +112,7 @@ app.post('/cloudflare', async (req, res) => {
}
let cacheKey, cached
if (data.mode === "iuam") {
if (CACHE_ENABLED && data.mode === "iuam") {
cacheKey = JSON.stringify(data)
cached = readCache(cacheKey)
@@ -147,7 +150,7 @@ app.post('/cloudflare', async (req, res) => {
.then(r => ({ ...r }))
.catch(err => ({ code: 500, message: err.message }))
if (!result.code || result.code === 200) {
if (CACHE_ENABLED && (!result.code || result.code === 200)) {
writeCache(cacheKey, result)
}
break