Add configurable cache TTL via environment variable
- IOR_CACHE_TTL environment variable to control cache duration - Set to 0 to disable caching (always fetch fresh) - Set to 60000 for 1 minute cache (useful during development) - Default remains 1 hour (3600000ms) - Improved logging to show when cache is disabled or expired
This commit is contained in:
@@ -31,7 +31,13 @@ const processedTypes = new Set();
|
||||
/**
|
||||
* Remote cache configuration
|
||||
*/
|
||||
const CACHE_TTL = 3600000; // 1 hour default TTL
|
||||
// Cache TTL: Use environment variable or default to 1 hour
|
||||
// Set IOR_CACHE_TTL=0 to always fetch fresh
|
||||
// Set IOR_CACHE_TTL=60000 for 1 minute cache (useful during development)
|
||||
const CACHE_TTL = process.env.IOR_CACHE_TTL !== undefined
|
||||
? parseInt(process.env.IOR_CACHE_TTL)
|
||||
: 3600000; // 1 hour default
|
||||
|
||||
// Use project-local cache directory instead of temp directory to avoid watchman issues
|
||||
const CACHE_DIR = path.join(process.cwd(), '.ior-cache', 'remote');
|
||||
|
||||
@@ -102,7 +108,12 @@ function getCachedRemoteComponent(ior) {
|
||||
}
|
||||
|
||||
// Check if cache entry is still valid
|
||||
if (Date.now() - entry.timestamp > entry.ttl) {
|
||||
if (CACHE_TTL === 0 || Date.now() - entry.timestamp > entry.ttl) {
|
||||
if (CACHE_TTL === 0) {
|
||||
console.log(`[IOR Resolver] Cache disabled (IOR_CACHE_TTL=0), fetching fresh: ${ior}`);
|
||||
} else {
|
||||
console.log(`[IOR Resolver] Cache expired for: ${ior}`);
|
||||
}
|
||||
remoteCache.delete(ior);
|
||||
// Try to delete the directory (non-blocking)
|
||||
if (entry.directory) {
|
||||
|
||||
Reference in New Issue
Block a user