Skip to content

feat: add output cache system with TTL and diff detection#554

Open
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/cache-system
Open

feat: add output cache system with TTL and diff detection#554
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/cache-system

Conversation

@bz00qa
Copy link

@bz00qa bz00qa commented Mar 13, 2026

Summary

  • cache.rs: File-based output cache with deterministic keys (command + cwd hash), configurable TTL, volatile command detection, and line-level diff between cached/current output
  • rtk cache-clear: CLI command to reset the cache
  • Tracking integration: New cache_hit column in SQLite — all gain/analytics queries exclude cache hits to keep savings stats accurate
  • Config: [cache] section in config.toml with enabled (default: true) and ttl_minutes (default: 5), overridable via RTK_CACHE and RTK_CACHE_TTL env vars

How it works

When proxy -f (from #553) or future commands use the cache:

  1. Compute deterministic key from command + working directory
  2. Check if cached output exists and is within TTL
  3. If cache hit: diff against current output, show only changes
  4. If cache miss: store filtered output for next invocation

Volatile commands (git status, ls, find, etc.) are never cached.

Tests

11 new tests covering key generation, volatile detection, diff computation, and truncation.

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets passes (no new warnings)
  • cargo test — 898 passed, 11 new cache tests all green
  • Manual: rtk cache-clear clears cache directory
  • Manual: verify [cache] section appears in rtk config

🤖 Generated with Claude Code

New cache module for caching filtered command output:
- File-based cache in ~/.local/share/rtk/cache/ with deterministic
  keys (command + cwd hash)
- Configurable TTL (default 5min) via config.toml or RTK_CACHE_TTL
  env var
- Enable/disable via config.toml or RTK_CACHE env var
- Volatile command detection (git status, ls, etc. are never cached)
- Line-level diff between cached and current output with truncation
- `rtk cache-clear` command to reset cache

Tracking integration:
- New cache_hit column in SQLite tracking database
- record_cache_hit() and track_cache_hit() methods
- All gain/analytics queries exclude cache hits (AND cache_hit = 0)
  to keep savings stats accurate
- get_cache_stats() for cache performance reporting

Config:
- CacheConfig struct in config.toml ([cache] section)
- enabled (default: true), ttl_minutes (default: 5)

11 tests for cache module, all existing tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
@bz00qa bz00qa force-pushed the feat/cache-system branch from 373d384 to 7cf47d0 Compare March 13, 2026 16:36
@bz00qa bz00qa changed the base branch from master to develop March 13, 2026 16:37
Signed-off-by: bZ00qa <167500396+bz00qa@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant