From 88d445efa2a1608369f4a4df4b46665ac4c6abb4 Mon Sep 17 00:00:00 2001 From: asmyshlyaev177 Date: Wed, 26 Aug 2026 20:53:52 +0400 Subject: [PATCH 1/2] fix: lru local cache eviction #71 --- CHANGELOG.md | 7 ++ README.md | 44 ++++--- package.json | 2 +- src/caching/local-cache.ts | 69 +++++++++-- src/cli-options.ts | 38 ++++++ src/cli.ts | 2 +- src/test/cli-options.test.ts | 22 ++++ src/test/local-cache.test.ts | 229 +++++++++++++++++++++++++++++++++++ src/util/fs.ts | 9 ++ 9 files changed, 396 insertions(+), 26 deletions(-) create mode 100644 src/test/local-cache.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f8baa1ddf..bd8b20798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Added + +- Local caches are now limited to the 2 most recently used entries per script, + instead of growing without bound. Set `WIREIT_CACHE_MAX_ENTRIES` to change the + limit, or to `infinity` for the previous behavior. See + [#71](https://github.com/google/wireit/issues/71). + ## [0.14.13] - 2026-06-23 ### Added diff --git a/README.md b/README.md index 945ddecbe..4a010051a 100644 --- a/README.md +++ b/README.md @@ -346,10 +346,21 @@ Local caching is enabled by default, unless the environment variable is detected. To force local caching, set `WIREIT_CACHE=local`. To disable local caching, set `WIREIT_CACHE=none`. -> ⚠️ Wireit does not currently limit the size of local caches. To free up this -> space, use `rm -rf .wireit/*/cache`. Automatic cache size limits will be added -> in an upcoming release, tracked at -> [wireit#71](https://github.com/google/wireit/issues/71). +Each script retains its 2 most recently used cache entries. Whenever a new entry +is written, any entries beyond that limit are deleted, least recently used +first. Because an entry is a full copy of the script's `output` files, this caps +a script's cache at roughly 2× the size of its output. + +To change the limit, set `WIREIT_CACHE_MAX_ENTRIES` to a positive integer, or to +`infinity` to retain every entry: + +```sh +export WIREIT_CACHE_MAX_ENTRIES=10 +``` + +Note the limit is applied per script, so a package with many cached scripts will +still use a multiple of this space. To free all of it at once, use +`rm -rf .wireit/*/cache`. ### GitHub Actions caching @@ -868,18 +879,19 @@ The following syntaxes can be used in the `wireit.