my website at ewancroft.uk
at main 34 lines 1.6 kB view raw
1import { env } from '$env/dynamic/private'; 2import { CACHE_TTL as DEFAULT_CACHE_TTL } from './cache.config'; 3 4/** 5 * Server-only cache configuration that can override defaults with environment variables 6 * This file should only be imported in server-side code (e.g., +page.server.ts, +layout.server.ts) 7 */ 8 9// Parse environment variable or use default (in milliseconds) 10const getEnvTTL = (key: string, defaultValue: number): number => { 11 const value = env[key]; 12 if (value) { 13 const minutes = parseInt(value, 10); 14 return isNaN(minutes) ? defaultValue : minutes * 60 * 1000; 15 } 16 return defaultValue; 17}; 18 19/** 20 * Cache TTL configuration with environment variable overrides 21 * Values are loaded from environment variables with fallbacks to defaults from cache.config.ts 22 */ 23export const CACHE_TTL = { 24 PROFILE: getEnvTTL('CACHE_TTL_PROFILE', DEFAULT_CACHE_TTL.PROFILE), 25 SITE_INFO: getEnvTTL('CACHE_TTL_SITE_INFO', DEFAULT_CACHE_TTL.SITE_INFO), 26 LINKS: getEnvTTL('CACHE_TTL_LINKS', DEFAULT_CACHE_TTL.LINKS), 27 MUSIC_STATUS: getEnvTTL('CACHE_TTL_MUSIC_STATUS', DEFAULT_CACHE_TTL.MUSIC_STATUS), 28 KIBUN_STATUS: getEnvTTL('CACHE_TTL_KIBUN_STATUS', DEFAULT_CACHE_TTL.KIBUN_STATUS), 29 TANGLED_REPOS: getEnvTTL('CACHE_TTL_TANGLED_REPOS', DEFAULT_CACHE_TTL.TANGLED_REPOS), 30 BLOG_POSTS: getEnvTTL('CACHE_TTL_BLOG_POSTS', DEFAULT_CACHE_TTL.BLOG_POSTS), 31 PUBLICATIONS: getEnvTTL('CACHE_TTL_PUBLICATIONS', DEFAULT_CACHE_TTL.PUBLICATIONS), 32 INDIVIDUAL_POST: getEnvTTL('CACHE_TTL_INDIVIDUAL_POST', DEFAULT_CACHE_TTL.INDIVIDUAL_POST), 33 IDENTITY: getEnvTTL('CACHE_TTL_IDENTITY', DEFAULT_CACHE_TTL.IDENTITY) 34} as const;