Cache Management
Optimize CDK Insights performance with intelligent caching. Learn how to configure, manage, and troubleshoot the analysis cache for your specific workflow.
š” CI/CD Note: CDK Insights automatically disables caching when it detects a CI environment. No configuration needed - fresh analysis runs on every CI build.
What is CDK Insights Caching?
How It Works
- Analysis results are stored locally
- Subsequent scans reuse cached data
- Cache expires based on TTL settings
- Cache is in-memory and clears on process restart
Benefits
- Faster analysis on repeated scans
- Reduced CPU and memory usage
- Lower network bandwidth usage
- Better developer experience
Caching Strategies
Aggressive Caching
TTL: 24 hoursCache everything for maximum speed
Best for:
Large projects with infrequent changes
Pros:
- Fastest analysis
- Minimal resource usage
Cons:
- May miss recent changes
- Requires manual cache clearing
{
"cache": {
"enabled": true,
"ttl": 86400000,
"maxSize": 2000
}
}Balanced Caching
TTL: 2 hoursBalance between speed and freshness
Best for:
Most development workflows
Pros:
- Good performance
- Reasonable freshness
Cons:
- May need periodic clearing
{
"cache": {
"enabled": true,
"ttl": 7200000,
"maxSize": 1000
}
}Conservative Caching
TTL: 30 minutesMinimal caching for maximum accuracy
Best for:
Critical security analysis
Pros:
- Always up-to-date
- No stale data
Cons:
- Slower analysis
- Higher resource usage
{
"cache": {
"enabled": true,
"ttl": 1800000,
"maxSize": 500
}
}No Caching
TTL: N/ADisable caching completely
Best for:
One-time analysis (CI/CD auto-disables cache)
Pros:
- Always fresh
- No cache management
Cons:
- Slowest analysis
- Highest resource usage
{
"cache": {
"enabled": false
}
}
// Note: In CI environments, cache is
// automatically disabledCache Operations
Check Cache Status
View current cache statistics and usage
Command:
cdk-insights cache-statusExample Output:
š Cache Status: š Cache directory: /Users/user/.cdk-insights/cache š Directory exists: Yes š Cache file exists: Yes š Cache file size: 45.2 KB āļø Cache enabled: Yes ā¹ļø Note: Current cache is in-memory and clears on process restart
Clear Cache
Remove all cached analysis results
Command:
cdk-insights clear-cacheExample Output:
šļø Clearing analysis cache... ā Analysis cache cleared successfully š Cache directory: /Users/user/.cdk-insights/cache š Cache status: No persistent cache files
Troubleshooting Cache Issues
Cache grows too large
Symptoms:
- Disk space warnings
- Slow cache operations
Solution:
Reduce cache maxSize or clear cache periodically
Prevention: Set up automated cache cleanup
Commands:
cdk-insights clear-cachecdk-insights cache-statusStale analysis results
Symptoms:
- Missing recent changes
- Outdated recommendations
Solution:
Clear cache or reduce TTL
Prevention: Use shorter TTL for active development
Commands:
cdk-insights clear-cachecdk-insights scan --no-cacheCache corruption
Symptoms:
- Analysis errors
- Unexpected behavior
Solution:
Clear cache completely
Prevention: Regular cache health checks
Commands:
cdk-insights clear-cacheCache not being used
Symptoms:
- Always slow analysis
- Cache shows as disabled
Solution:
Verify cache is enabled in configuration
Prevention: Monitor cache statistics
Commands:
cdk-insights cache-statusCheck .cdk-insights.jsonCache Best Practices
Monitor Cache Performance
Regularly check cache status and size
Action:
Run cache-status weekly
Benefit: Identify optimization opportunities
Use Appropriate TTL
Set TTL based on your development cycle
Action:
2-4 hours (7,200,000-14,400,000 ms) for active development
Benefit: Balance performance and freshness
CI/CD Auto-Disables Cache
Cache is automatically disabled in CI environments
Action:
No action needed - CDK Insights detects CI and skips caching
Benefit: Ensures fresh analysis on every CI run without extra configuration
Configure Cache Limits
Set appropriate maxSize to control memory usage
Action:
Set maxSize based on project complexity
Benefit: Prevent excessive memory consumption
Ready to Optimize Your Cache?
Start by checking your current cache status and configuring the optimal strategy for your workflow.