Files
dashcaddy/dashcaddy-api/cache-config.js

62 lines
1.8 KiB
JavaScript

// Cache Configuration Module
// Provides LRU cache configurations to prevent memory leaks
const { LRUCache } = require('lru-cache');
/**
* Cache configuration presets for different data types
* All TTL values are in milliseconds
*/
const CACHE_CONFIGS = {
// App session cookies (login tokens for SSO)
appSessions: {
max: 500, // Max 500 different services
ttl: 60 * 60 * 1000, // 1 hour TTL
updateAgeOnGet: true, // Refresh TTL on access
ttlAutopurge: true // Auto-cleanup expired entries
},
// IP-based router sessions (Frontier NVG468MQ)
ipSessions: {
max: 1000, // Support up to 1000 IP addresses
ttl: 24 * 60 * 60 * 1000, // 24 hour TTL
updateAgeOnGet: true,
ttlAutopurge: true
},
// DNS server authentication tokens (Technitium)
dnsTokens: {
max: 50, // Max 50 DNS servers
ttl: 6 * 60 * 60 * 1000, // 6 hour TTL (matches SESSION_TTL.DNS_TOKEN)
updateAgeOnGet: false, // Don't refresh - tokens have fixed expiry
ttlAutopurge: true
},
// Tailscale network status
tailscaleStatus: {
max: 1, // Only one status object
ttl: 60 * 1000, // 1 minute TTL
updateAgeOnGet: false,
ttlAutopurge: true
},
// Tailscale API responses (devices, ACLs)
tailscaleAPI: {
max: 5, // devices + ACL + misc
ttl: 5 * 60 * 1000, // 5 min (matches sync interval)
updateAgeOnGet: false,
ttlAutopurge: true
}
};
/**
* Factory function to create a configured LRU cache
* @param {Object} config - Cache configuration from CACHE_CONFIGS
* @returns {LRUCache} Configured LRU cache instance
*/
function createCache(config) {
return new LRUCache(config);
}
module.exports = { CACHE_CONFIGS, createCache };