diff --git a/README.md b/README.md index fb3314a..f0f8c01 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index e00fbe3..273b4ce 100644 --- a/index.js +++ b/index.js @@ -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