Add size-bounded GC of the repo contents cache
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
Let users put a size ceiling on the repo contents cache. As far as I can tell, today, the only eviction signal is age (`--repo_contents_cache_gc_max_age`), so on busy workspaces the cache grows without bound until the age window kicks in. A companion size-based knob would let users say "keep this cache under 20 GB" and have Bazel evict the oldest entries to honour it: matching the pair of knobs the disk cache already exposes (added in #23833).
### Which category does this issue belong to?
Performance
### What underlying problem are you trying to solve with this feature?
The repo contents cache (introduced via #12227, made GC-aware in #26080) only supports **age-based** eviction today. A few workflow patterns combine to make the cache grow faster than the age window evicts:
- Multiple workspaces / `git worktree` checkouts sharing one `--repo_contents_cache`. Every workspace adds entries; none individually feels the cost.
- `MODULE.bazel` churn: version bumps, added or removed modules shifts predeclared-input-hashes. Old entries are no longer referenced but still don't age out for 14 days.
- Every touch resets an entry's age clock, so the cache grows with the working-set size of all dependency churn over the age window, not with what's in use today.
Concrete: the `contents/` directory under one of my caches grew to ~91 GB within a single 14-day window before disk pressure forced a manual `rm -rf` (on a dev laptop). A user wanting to keep it under (say) 20 GB has no tool for it short of deleting the directory by hand.
The disk cache already has both knobs, this asks for parity.
### Which operating system are you running Bazel on?
macOS 26.4.1
### What is the output of `bazel info release`?
release 8.7.0 (currently upgrading to 9)
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
cc:
- @Wyverald (PR #26080, original repo contents cache GC)
- @tjgq (PR #23833, disk cache GC pattern this mirrors)
Contributor guide
Research direction
Start by reading the repo contents cache GC work from PR #26080 and the disk cache size-based GC pattern from PR #23833. Trace how --repo_contents_cache_gc_max_age currently controls eviction, then determine where a size ceiling and oldest-entry eviction fit. Done means users can configure a cache size limit and the repo contents cache evicts entries to honor it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100