Skip to main content
Skip to main content

Cache Management

Optimize CDK Insights performance with intelligent caching. Learn how to configure, manage, and troubleshoot the analysis cache for your specific workflow.

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 hours

Cache 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 hours

Balance 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 minutes

Minimal 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/A

Disable caching completely

Best for:

CI/CD pipelines or one-time analysis

Pros:

  • Always fresh
  • No cache management

Cons:

  • Slowest analysis
  • Highest resource usage
{ "cache": { "enabled": false } }

Cache Operations

Check Cache Status

View current cache statistics and usage

Command:

cdk-insights cache-status

Example 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-cache

Example 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-cache
cdk-insights cache-status

Stale 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-cache
cdk-insights scan --no-cache

Cache corruption

Symptoms:

  • Analysis errors
  • Unexpected behavior

Solution:

Clear cache completely

Prevention: Regular cache health checks

Commands:

cdk-insights clear-cache

Cache 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-status
Check .cdk-insights.json

Cache 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

Clear Cache in CI/CD

Start with fresh cache in automated pipelines

Action:

Add clear-cache to CI/CD scripts

Benefit: Ensure consistent, up-to-date results

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.