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.

๐Ÿ’ก In-memory cache: The analysis cache lives in process memory and clears on process restart. There's no persistent cache file on disk, and CI runs always start with a fresh cache because each job is a new process.

What is CDK Insights Caching?

How It Works

  • Analysis results are cached in process memory
  • 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:

One-time analysis or when you need every scan to be fully fresh

Pros:

  • Always fresh
  • No cache management

Cons:

  • Slowest analysis
  • Higher AI credit usage on repeat scans
{ "cache": { "enabled": false } }

Cache Operations

Check Cache Status

View current cache configuration

Command:

cdk-insights cache-status

Example Output:

๐Ÿ“Š Cache Status:
โš™๏ธ  Cache enabled: Yes
โฑ๏ธ  TTL: 7,200,000 ms (2h)
๐Ÿ“ฆ Max entries: 1000
โ„น๏ธ  Cache is in-memory and clears on process restart

Clear Cache

Drop in-process cached analysis entries before the next run

Command:

cdk-insights clear-cache

Example Output:

๐Ÿ—‘๏ธ  Clearing analysis cache...
โœ… Cache cleared successfully
โ„น๏ธ  Cache is in-memory โ€” restarting the CLI also clears it

Troubleshooting Cache Issues

Cache uses too much memory

Symptoms:

  • Higher resident memory on long-running CLI sessions
  • Slow cache lookups

Solution:

Reduce cache.maxSize in .cdk-insights.json

Prevention: Pick a maxSize proportional to project size; the in-memory cache resets per process

Commands:

cdk-insights cache-status
cdk-insights scan --noCache

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 --noCache

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

CI Runs Get Fresh Caches

Cache is in-memory and lives only for the duration of one CLI invocation

Action:

No action needed โ€” every CI job starts a fresh process and therefore a fresh cache

Benefit: Each CI run analyses against the current state without any leftover entries from previous runs

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.