diff --git a/.env.sample b/.env.sample index b74f346..9fd77ea 100644 --- a/.env.sample +++ b/.env.sample @@ -19,3 +19,6 @@ HTTPS_CERT_PATH="/some/where.crt" ENABLED_CORS="no" # cors ('yes' or 'no'), CORS_ORIGIN is required ENABLED_CORS_ORIGIN_CHECK="no" # is the API public to every client ('yes' or 'no') CORS_ORIGIN="https://example.org" + +# settings +CACHE_MAX_AGE="86400" # cache max age in seconds diff --git a/src/init/cache.mjs b/src/init/cache.mjs index 3eb90e0..c7ac9fe 100644 --- a/src/init/cache.mjs +++ b/src/init/cache.mjs @@ -1,10 +1,12 @@ // node-cache is an in-memory cache. // Import modules +import {getMust} from "../config.mjs"; import NodeCache from "node-cache"; // Initialize node-cache -const cache = new NodeCache({stdTTL: 7200}); +const stdTTL = getMust("CACHE_MAX_TTL"); +const cache = new NodeCache({stdTTL: parseInt(stdTTL)}); // Export as a function named useCache export const useCache = () => cache;