Skip to content

Commit

Permalink
feat(cache.mjs): make cache stdTTL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonictw committed Aug 26, 2024
1 parent 507bd03 commit b17aca8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/init/cache.mjs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b17aca8

Please sign in to comment.