|
| 1 | +# Caching Strategy |
| 2 | + |
| 3 | +git-this-bread tools use a common caching strategy for expensive operations. |
| 4 | + |
| 5 | +## Cache Location |
| 6 | + |
| 7 | +All caches live under the XDG cache directory: |
| 8 | + |
| 9 | +``` |
| 10 | +~/.cache/git-this-bread/ # or $XDG_CACHE_HOME/git-this-bread/ |
| 11 | +├── git-explain/ |
| 12 | +│ └── llm-advice/ # LLM advice responses |
| 13 | +│ └── {state_hash}.json |
| 14 | +└── gh-wtfork/ |
| 15 | + └── prs/ # Merged/closed PR data |
| 16 | + └── {owner}_{repo}.json |
| 17 | +``` |
| 18 | + |
| 19 | +## Cache Behavior |
| 20 | + |
| 21 | +### Bypass without invalidation |
| 22 | + |
| 23 | +All tools support `--no-cache` which: |
| 24 | +- **Skips reading** from cache (fetches fresh data) |
| 25 | +- **Still writes** to cache (refreshes it for next time) |
| 26 | + |
| 27 | +This ensures running with `--no-cache` doesn't leave you with stale data on the next normal run. |
| 28 | + |
| 29 | +### Per-tool strategies |
| 30 | + |
| 31 | +#### git-explain (LLM advice) |
| 32 | + |
| 33 | +- **What's cached**: LLM responses for repo analysis |
| 34 | +- **Cache key**: Hash of repo state (branch, ahead/behind, dirty files, etc.) |
| 35 | +- **Invalidation**: Automatic - cache key changes when repo state changes |
| 36 | +- **TTL**: None (state-based invalidation) |
| 37 | + |
| 38 | +#### gh-wtfork (PR data) |
| 39 | + |
| 40 | +- **What's cached**: Merged and closed PRs only |
| 41 | +- **Cache key**: Upstream repo name (`owner/repo`) |
| 42 | +- **Invalidation**: Never - merged/closed PRs don't change |
| 43 | +- **TTL**: None (permanent for merged/closed) |
| 44 | + |
| 45 | +Open PRs are always fetched fresh. The cache provides: |
| 46 | +- Faster access to historical PR data |
| 47 | +- Fallback if API is rate-limited |
| 48 | +- Accumulates PR history over time |
| 49 | + |
| 50 | +## Implementation |
| 51 | + |
| 52 | +Tools should use the common cache directory pattern: |
| 53 | + |
| 54 | +```go |
| 55 | +func getCacheDir(tool string) (string, error) { |
| 56 | + cacheHome := os.Getenv("XDG_CACHE_HOME") |
| 57 | + if cacheHome == "" { |
| 58 | + home, err := os.UserHomeDir() |
| 59 | + if err != nil { |
| 60 | + return "", err |
| 61 | + } |
| 62 | + cacheHome = filepath.Join(home, ".cache") |
| 63 | + } |
| 64 | + return filepath.Join(cacheHome, "git-this-bread", tool), nil |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +## Clearing the cache |
| 69 | + |
| 70 | +To clear all caches: |
| 71 | + |
| 72 | +```bash |
| 73 | +rm -rf ~/.cache/git-this-bread/ |
| 74 | +``` |
| 75 | + |
| 76 | +To clear a specific tool's cache: |
| 77 | + |
| 78 | +```bash |
| 79 | +rm -rf ~/.cache/git-this-bread/gh-wtfork/ |
| 80 | +rm -rf ~/.cache/git-this-bread/git-explain/ |
| 81 | +``` |
0 commit comments