Skip to content

Commit e0014f9

Browse files
jdeveraclaude
andcommitted
docs: add caching strategy documentation
- Add docs/caching.md documenting common cache behavior - Update AGENTS.md with caching section and gh-wtfork - Update brew install to single formula Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7598572 commit e0014f9

2 files changed

Lines changed: 89 additions & 4 deletions

File tree

AGENTS.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ mise run lint # golangci-lint
1414

1515
- git-explain — repo status analyzer (see cmd/git-explain/AGENTS.md)
1616
- git-as — identity tools bundle: git-id, git-as, gh-as (see cmd/git-id/AGENTS.md)
17+
- gh-wtfork — GitHub fork analyzer
18+
19+
## Caching
20+
21+
Tools cache expensive operations in `~/.cache/git-this-bread/`. See `docs/caching.md` for strategy.
1722

1823
## Releases
1924

20-
GoReleaser builds binaries and Homebrew formulas on tag push:
25+
GoReleaser builds binaries and Homebrew formula on tag push:
2126

2227
```
2328
git tag v1.0.0 && git push --tags
2429
```
2530

26-
Formulas pushed to `jdevera/homebrew-tap`. Install with:
31+
Formula pushed to `jdevera/homebrew-tap`. Install with:
2732

2833
```
29-
brew install jdevera/tap/git-explain
30-
brew install jdevera/tap/git-as
34+
brew install jdevera/tap/git-this-bread
3135
```
3236

3337
## Test Helpers

docs/caching.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)