After the DC-005 module reorganization (41 files moved into src/ subdirs),
138 test suites failed because the refactor script's path-rewrite logic
missed three categories:
1. Files inside src/ doing 'require("./src/...")' — should be 'require("../...")'
2. Files in src/X/Y/ doing 'require("../../../src/...")' — should be 'require("../../...")'
3. Test files in __tests__/ with leftover 'require("../../../src/...")' paths
Root cause: the original refactor script ran before all files were moved,
so it computed relative paths against stale filesystem state.
Result:
- 30/30 test suites pass
- 879/879 tests pass (was: 18/30 suites, 614/687 tests)
Also fixed:
- routes/apps/restore.js: wrong responses import path
- routes/*/*.js: '../../src/utilities/X' → '../src/utilities/X' (depth 2 routes)
62 lines
1.8 KiB
JavaScript
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 };
|