How Caching Works
Vectra Guard uses intelligent caching to dramatically speed up repeated command executions. When a command runs in the sandbox, its inputs and outputs are cached, allowing subsequent identical commands to return instantly.
Cache Flow
- Command is received with inputs and environment
- Cache key is generated from command hash + input hash
- Cache is checked for matching entry
- If found: return cached result instantly (0.25s)
- If not found: execute in sandbox, cache result, return (2.5s)
Cache Key Generation
Cache keys are generated from multiple factors to ensure accuracy and prevent stale results.
# Cache key includes:
# 1. Command string (exact match required)
# 2. Command arguments
# 3. Working directory
# 4. Environment variables (selected)
# 5. Input file hashes (if any)
# 6. Sandbox image version
# Example cache key components:
Command: "npm install"
Args: ["express"]
CWD: "/project"
Env: {"NODE_ENV": "production"}
Input files: ["package.json" (hash: abc123...)]
# Combined hash: sha256(command + args + cwd + env + files)Note: Even a small change in command, arguments, or inputs will generate a different cache key and trigger a fresh execution.
Cache Strategies
Choose a caching strategy that matches your workflow and performance needs.
Smart (Default)
Intelligent caching that balances performance and freshness. Caches most commands but invalidates on dependency changes.
sandbox:
enable_cache: true
cache_strategy: smart
cache_ttl: 3600 # 1 hourBest for: Most development workflows. Automatically invalidates when package files change.
Aggressive
Maximum caching. Caches everything possible with longer TTL. Use when commands are deterministic.
sandbox:
enable_cache: true
cache_strategy: aggressive
cache_ttl: 86400 # 24 hours
cache_invalidation: manualBest for: CI/CD pipelines, deterministic builds, testing.
Conservative
Minimal caching. Only caches safe, read-only commands. Shorter TTL.
sandbox:
enable_cache: true
cache_strategy: conservative
cache_ttl: 300 # 5 minutes
cache_readonly_only: trueBest for: When you need fresh results, dynamic content, or are unsure about command determinism.
Cache Management
Manage your cache with built-in commands for inspection, invalidation, and cleanup.
# View cache statistics
vg cache stats --path .
# Output:
# Cache location: .vectra-guard/cache/
# Total entries: 1,234
# Cache size: 45.2 MB
# Hit rate: 87.3%
# Oldest entry: 2 days ago
# Newest entry: 5 minutes ago
# Clear all cache
vg cache clear --path .
# Clear cache for specific command
vg cache clear --path . --command "npm install"
# Invalidate cache (mark as stale)
vg cache invalidate --path . --pattern "npm:*"
# Prune old entries
vg cache prune --path . --max-age 7dPerformance Impact
Caching provides significant performance improvements for repeated commands.