Skip to content

Build Cache

wody edited this page May 24, 2026 · 2 revisions

Build Cache Management

Introduced in v0.28.0. View and selectively clean Gradle / Android / npm caches at /settings/cache (left nav: "빌드 캐시").

Why

After a few months of regular use, the biggest disk consumers are:

Directory Typical size Use
~/.gradle/caches/ 1–4 GB downloaded JAR/AAR dependencies, Maven Local
~/.gradle/daemon/ 50–500 MB JVM warm pool, daemon logs
~/.android/cache/ 100 MB–2 GB SDK manager cache, AVD snapshots
~/.npm/_cacache/ 200 MB–1 GB npm package + tarball cache (MCP installs)

The /settings/cache page measures each on demand (Files.walk + size sum) and offers per-target "정리" buttons. Clicking clears the contents of the directory but leaves the directory itself (so Gradle/npm doesn't panic about a missing path).

When to clean

  • Disk usage alert fired (v0.29.0+ — see Disk Monitor) and you don't want to immediately upgrade the host.
  • Suspected cache corruption — Gradle "could not resolve" errors that re-running doesn't fix.
  • Before a snapshot / backup — caches are reproducible from the network, so dropping them shrinks your tar by gigabytes.

When NOT to clean

  • A build is currently running. Gradle holds file locks on cache entries; cleaning mid-build won't crash anything (the routine catches the resulting IOException per-file), but you'll get a half-cleared cache and the running build may fail in unpredictable ways.
  • You're about to fly / go offline. First builds after a clean re-fetch every dependency; budget 5–15 min on a slow connection.

What happens internally

BuildCacheService.cleanup(target):

  1. Resolves the path against userHome (~/.gradle/caches, etc.).
  2. Files.walk(path).sorted(Comparator.reverseOrder()) — bottom-up.
  3. For each entry (not the root itself): Files.delete. Catches per-file exceptions and continues (so a locked file won't abort the whole walk).
  4. Returns (deletedFiles, freedBytes, errorMessage).

The walk is sequential — for very large caches this can take 10–30 s. No spinner today; the form just blocks until done.

Safety

  • The target list is a fixed enum (GRADLE_CACHES, GRADLE_DAEMON, ANDROID_CACHE, NPM_CACHE) — no arbitrary path is accepted from the form, so there's no path-traversal vector.
  • CSRF protects the POST. JS confirm dialog ("다음 빌드에서 재다운로드 발생합니다") makes accidental clicks unlikely.
  • Permission errors (files owned by another UID) are silently skipped; the result row reports only what actually got removed.

Roadmap

  • Async cleanup with progress bar (long walks block the form thread).
  • Optional auto-cleanup schedule when disk usage > N% — would combine with the disk monitor's existing alert hook.

Clone this wiki locally