cache-verdict 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +311 -2
- package/bin/cache-verdict.mjs +383 -0
- package/examples/npm-build-cache/README.md +95 -0
- package/examples/npm-build-cache/build.mjs +25 -0
- package/examples/npm-build-cache/package.json +10 -0
- package/examples/npm-build-cache/src/input.txt +5 -0
- package/examples/run.mjs +63 -0
- package/lib/config.mjs +141 -0
- package/lib/detect.mjs +647 -0
- package/lib/glob.mjs +192 -0
- package/lib/key.mjs +52 -0
- package/lib/ledger.mjs +357 -0
- package/lib/report.mjs +144 -0
- package/lib/run.mjs +204 -0
- package/package.json +41 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 WJDdidi-1
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,312 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cache-verdict
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/WJDdidi-1/cache-verdict/blob/main/docs/releases/v0.1.0.md)
|
|
4
|
+
|
|
5
|
+
Times build-cache cold vs warm runs and says whether the cache pays.
|
|
6
|
+
|
|
7
|
+
## Who it is for
|
|
8
|
+
|
|
9
|
+
Maintainers of CI-heavy Rust, Gradle, Next.js, npm, Python, and Go repos whose caches report hits but builds remain slow, stale, or restore nothing.
|
|
10
|
+
|
|
11
|
+
## The problem
|
|
12
|
+
|
|
13
|
+
Teams add a cache, watch the hit counter, and still ship slow or stale builds: a warm build over a cache from another pipeline can be slower than a cold one (vercel/next.js#99579). A hit count says nothing about whether the cache is paying for itself, so nobody can decide whether to keep or drop it (wbskt/Wbskt#168).
|
|
14
|
+
|
|
15
|
+
## Why not the obvious answer
|
|
16
|
+
|
|
17
|
+
actions/cache, Swatinem/rust-cache, and gradle/actions/setup-gradle only store and restore artifacts and report hit/miss; sccache --show-stats counts compiler hits but ignores restore cost and the end-to-end build; hyperfine times commands but not cache states. None answers whether a given cache key is net-positive for this build.
|
|
18
|
+
|
|
19
|
+
## Releases
|
|
20
|
+
|
|
21
|
+
This tree is version **0.1.0**. Release tags follow `v<version>`, so its tag is
|
|
22
|
+
`v0.1.0`. The [v0.1.0 release notes](https://github.com/WJDdidi-1/cache-verdict/blob/main/docs/releases/v0.1.0.md)
|
|
23
|
+
describe what shipped and how it was verified;
|
|
24
|
+
[docs/RELEASING.md](https://github.com/WJDdidi-1/cache-verdict/blob/main/docs/RELEASING.md)
|
|
25
|
+
is the checklist for creating the tag, the GitHub release, and the npm publish.
|
|
26
|
+
Notes for every version live in
|
|
27
|
+
[docs/releases/](https://github.com/WJDdidi-1/cache-verdict/tree/main/docs/releases/).
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install -g cache-verdict
|
|
33
|
+
cache-verdict --version
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Requires Node.js 18 or newer. The package has no runtime dependencies.
|
|
37
|
+
|
|
38
|
+
To install the current checkout before a release is on npm:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npm install -g .
|
|
42
|
+
cache-verdict --version
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To install the exact tarball that CI verifies:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm pack
|
|
49
|
+
npm install -g ./cache-verdict-0.1.0.tgz
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The only files `cache-verdict` writes inside a project are `.cache-verdict.json` and the `.cache-verdict/` measurement directory.
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
# Detect the build system and write a reviewable config.
|
|
58
|
+
cache-verdict init
|
|
59
|
+
|
|
60
|
+
# Read command, inputs, and cachePath; edit anything that looks wrong.
|
|
61
|
+
cat .cache-verdict.json
|
|
62
|
+
|
|
63
|
+
# Take a cold sample, then a warm sample using the stored cache.
|
|
64
|
+
cache-verdict run
|
|
65
|
+
cache-verdict run
|
|
66
|
+
|
|
67
|
+
# See the numbers and one verdict.
|
|
68
|
+
cache-verdict report
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`init` understands Cargo, Gradle, Next.js, npm (including pnpm, Yarn, and Bun lockfiles), Python, and Go. When several build systems match, pass `--ecosystem` to choose one. `init` never overwrites a reviewed config without `--force`.
|
|
72
|
+
|
|
73
|
+
## Run the example
|
|
74
|
+
|
|
75
|
+
[`examples/npm-build-cache/`](examples/npm-build-cache/) is a tiny npm project with a deliberately slow cold build and a fast warm build. From a checkout:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
npm run example
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The runner copies the example to a temporary directory, then runs `init`, two `run` samples, and `report` with this checkout's CLI. The temporary copy is removed afterwards, so nothing is written into the repository. The first sample is a cold miss, the second restores the stored cache, and the report should say `cache-pays`.
|
|
82
|
+
|
|
83
|
+
To run the same flow by hand and inspect the config, ledger, and stored cache, see [the example README](examples/npm-build-cache/README.md).
|
|
84
|
+
|
|
85
|
+
## A real session
|
|
86
|
+
|
|
87
|
+
Below is an actual run on a small npm demo project (macOS, Node 24): a `build` script in `package.json`, two files under `src/`, and a build that keeps a local cache under `node_modules/.cache`. Timings differ by machine; the verdict is computed from the medians in the ledger.
|
|
88
|
+
|
|
89
|
+
```console
|
|
90
|
+
$ cache-verdict init
|
|
91
|
+
Detected npm from package.json.
|
|
92
|
+
Wrote .cache-verdict.json.
|
|
93
|
+
note: npm's download cache defaults to ~/.npm; set npm_config_cache=.npm in CI to keep it project-local and measurable.
|
|
94
|
+
Review "command", "inputs", and "cachePath" before sampling.
|
|
95
|
+
|
|
96
|
+
$ cache-verdict run
|
|
97
|
+
|
|
98
|
+
> build
|
|
99
|
+
> node build.mjs
|
|
100
|
+
|
|
101
|
+
built from source
|
|
102
|
+
cache-verdict: MISS (cold)
|
|
103
|
+
key: sha256:7daa0feeabc43045ad5ee427775d0f9a302c6bc0b725cedc95b642283d102181
|
|
104
|
+
command: npm run build
|
|
105
|
+
restore: 0.0 ms
|
|
106
|
+
build: 416.6 ms
|
|
107
|
+
total: 416.6 ms
|
|
108
|
+
size: 105 bytes
|
|
109
|
+
|
|
110
|
+
$ cache-verdict run
|
|
111
|
+
|
|
112
|
+
> build
|
|
113
|
+
> node build.mjs
|
|
114
|
+
|
|
115
|
+
built from cache
|
|
116
|
+
cache-verdict: HIT (warm)
|
|
117
|
+
key: sha256:7daa0feeabc43045ad5ee427775d0f9a302c6bc0b725cedc95b642283d102181
|
|
118
|
+
command: npm run build
|
|
119
|
+
restore: 0.8 ms
|
|
120
|
+
build: 166.9 ms
|
|
121
|
+
total: 167.7 ms
|
|
122
|
+
size: 105 bytes
|
|
123
|
+
|
|
124
|
+
$ cache-verdict report
|
|
125
|
+
Runs: 2 (1 hit, 1 miss)
|
|
126
|
+
Hit rate: 50.0%
|
|
127
|
+
Median cold total: 416.6 ms
|
|
128
|
+
Median warm total: 167.7 ms
|
|
129
|
+
Restore cost: 0.8 ms
|
|
130
|
+
Net ms per hit: 248.9 ms
|
|
131
|
+
Cache size: 105 B across 1 stored key
|
|
132
|
+
Verdict: cache-pays
|
|
133
|
+
Reason: warm builds are 248.9 ms faster per hit after paying the restore cost
|
|
134
|
+
|
|
135
|
+
$ cache-verdict check >/dev/null && echo "the cache pays"
|
|
136
|
+
the cache pays
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The warm run restored the cached artifact in 0.8 ms and skipped the expensive part of the build, so a hit is worth about 249 ms here. `check` exits 0 in this state, 2 when the cache loses, and 3 before there are enough samples to decide.
|
|
140
|
+
|
|
141
|
+
## What the MVP does
|
|
142
|
+
|
|
143
|
+
- `cache-verdict init` detects Cargo, Gradle, Next.js, npm, Python, or Go and writes a reviewable `.cache-verdict.json`.
|
|
144
|
+
- `cache-verdict run` content-addresses the declared inputs, moves declared cache dirs aside, restores the stored cache for that exact key when it exists, times the build from that known state, stores the produced artifacts, and appends one sample to `.cache-verdict/ledger.jsonl`.
|
|
145
|
+
- `cache-verdict report` prints hit rate, median cold vs warm totals, restore cost, net ms per hit, cache size, and one verdict: `cache-pays`, `cache-costs`, `cache-churns`, `cache-never-hits`, or `cache-unobserved`.
|
|
146
|
+
- `cache-verdict check` exits 2 on a losing, churning, or unobserved cache and 3 when more runs are needed, so CI can gate on the verdict.
|
|
147
|
+
- `cache-verdict prune --keep N` evicts least-recently-used stored keys; `run --cold` adds a baseline sample without wedging the next hit.
|
|
148
|
+
|
|
149
|
+
## The config
|
|
150
|
+
|
|
151
|
+
`init` writes something like this; you can edit it by hand or regenerate it with `--force`:
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"schemaVersion": 1,
|
|
156
|
+
"ecosystem": "cargo",
|
|
157
|
+
"displayName": "Cargo",
|
|
158
|
+
"command": "cargo build",
|
|
159
|
+
"inputs": ["Cargo.toml", "Cargo.lock", "src/**"],
|
|
160
|
+
"cachePath": ["target"],
|
|
161
|
+
"detectedFrom": ["Cargo.toml"]
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- `command` is the real build to time. It runs through the platform shell from the project directory.
|
|
166
|
+
- `inputs` are paths or globs. Their contents, the command, and the declared cache paths are hashed into the cache key. A key never silently reuses a cache measured for a different command.
|
|
167
|
+
- `cachePath` is what cache-verdict moves aside, restores, sizes, and stores. It may be a directory, a file, a glob such as `**/__pycache__`, or an environment-expanded path such as `$GOCACHE`. An empty list is reported as `cache-unobserved`.
|
|
168
|
+
|
|
169
|
+
## What the verdicts mean
|
|
170
|
+
|
|
171
|
+
| Verdict | Meaning |
|
|
172
|
+
| --- | --- |
|
|
173
|
+
| `cache-pays` | A warm hit is faster than the cold baseline, after paying the measured restore cost. |
|
|
174
|
+
| `cache-costs` | A warm hit is not faster than cold; the cache is not paying for itself. |
|
|
175
|
+
| `cache-churns` | More than one key appears in the samples, so the key changes too often to accumulate hits reliably. |
|
|
176
|
+
| `cache-never-hits` | At least two samples were taken and none restored a stored cache. |
|
|
177
|
+
| `cache-unobserved` | There is no cache path, no ledger, only one cold sample, or no cold baseline yet. |
|
|
178
|
+
|
|
179
|
+
The report uses medians so one noisy sample does not decide the verdict. `Net ms per hit` is the median cold total minus the median warm total, where the warm total already includes restore time.
|
|
180
|
+
|
|
181
|
+
## The ledger and stored cache
|
|
182
|
+
|
|
183
|
+
Each sample is one JSON object on its own line in `.cache-verdict/ledger.jsonl`:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"schemaVersion": 1,
|
|
188
|
+
"key": "sha256:...",
|
|
189
|
+
"hit": true,
|
|
190
|
+
"cold": false,
|
|
191
|
+
"warm": true,
|
|
192
|
+
"buildMs": 1831.2,
|
|
193
|
+
"restoreMs": 412.7,
|
|
194
|
+
"totalMs": 2243.9,
|
|
195
|
+
"sizeBytes": 104857600,
|
|
196
|
+
"restoreSizeBytes": 104857600,
|
|
197
|
+
"stored": true,
|
|
198
|
+
"command": "cargo build"
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Stored artifacts live under `.cache-verdict/store/<key>/`. Add `.cache-verdict/` to `.gitignore`; it is measurement state, not source. Moving the declared cache dirs aside is what makes a cold sample genuinely cold. `prune` only removes stored keys, never ledger history.
|
|
203
|
+
|
|
204
|
+
## CI gating
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
cache-verdict run
|
|
208
|
+
cache-verdict run
|
|
209
|
+
cache-verdict check
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`check` prints the same report and then:
|
|
213
|
+
|
|
214
|
+
- exits 0 for `cache-pays`,
|
|
215
|
+
- exits 2 for `cache-costs`, `cache-churns`, `cache-never-hits`, or `cache-unobserved`,
|
|
216
|
+
- exits 3 when more samples are needed before a verdict is possible.
|
|
217
|
+
|
|
218
|
+
To add a fresh cold baseline in a pipeline without losing the stored cache that the next run should hit:
|
|
219
|
+
|
|
220
|
+
```sh
|
|
221
|
+
cache-verdict run --cold
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## How we know it works
|
|
225
|
+
|
|
226
|
+
`npm test` runs 25 tests. CI runs the suite on Ubuntu, macOS, and Windows with Node.js 18, 20, and 22, then packs the tarball, installs it into a clean project, and runs the installed `cache-verdict` command. The end-to-end tests build throwaway projects and assert:
|
|
227
|
+
|
|
228
|
+
- an identical key restores on the second run and reports `cache-pays` with exit 0;
|
|
229
|
+
- a slower warm build reports `cache-costs` with exit 2;
|
|
230
|
+
- changing inputs produce multiple keys and report `cache-churns`;
|
|
231
|
+
- a cache that is never restored after two samples reports `cache-never-hits`;
|
|
232
|
+
- an empty `cachePath` reports `cache-unobserved`;
|
|
233
|
+
- `run --cold` records a baseline while still allowing the next normal run to hit;
|
|
234
|
+
- `prune --keep` evicts least-recently-used keys;
|
|
235
|
+
- `run` refuses a cachePath that would move the project itself;
|
|
236
|
+
- `report --json` and the initial "not enough samples" check behave as documented.
|
|
237
|
+
|
|
238
|
+
The same flow by hand:
|
|
239
|
+
|
|
240
|
+
```sh
|
|
241
|
+
cache-verdict init && cache-verdict run && cache-verdict run && cache-verdict report
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## FAQ
|
|
245
|
+
|
|
246
|
+
### Does cache-verdict run my build?
|
|
247
|
+
|
|
248
|
+
Yes. `run` executes the `command` from `.cache-verdict.json` through your platform shell in the project directory and times that process. Inspect the detected command, inputs, and cache paths before the first sample:
|
|
249
|
+
|
|
250
|
+
```sh
|
|
251
|
+
cache-verdict init --dry-run
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
`--dry-run` prints the config to stdout and writes nothing.
|
|
255
|
+
|
|
256
|
+
### How many runs do I need before the verdict means anything?
|
|
257
|
+
|
|
258
|
+
One cold sample and one warm sample. The first `run` misses and stores the cache; the second restores that cache and hits. Until both exist, `check` exits 3 instead of inventing a verdict:
|
|
259
|
+
|
|
260
|
+
```sh
|
|
261
|
+
cache-verdict run && cache-verdict run && cache-verdict check
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Why does my report say `cache-unobserved`?
|
|
265
|
+
|
|
266
|
+
There are four causes: `cachePath` is empty, no samples have been recorded, only one cold sample exists, or a warm sample arrived without a cold baseline. `report` prints the exact reason. Fix `cachePath` in `.cache-verdict.json` if it is empty, otherwise add the missing sample:
|
|
267
|
+
|
|
268
|
+
```sh
|
|
269
|
+
cache-verdict run --cold
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Does `run` replace or delete my real cache directory?
|
|
273
|
+
|
|
274
|
+
It moves each declared `cachePath` aside, restores a previously stored cache for the current key if one exists (a normal `run`, not `--cold`), then times the build and leaves the directory as that run produced it. The pre-run contents are put back only if the build fails. Review the declared paths first:
|
|
275
|
+
|
|
276
|
+
```sh
|
|
277
|
+
cat .cache-verdict.json
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Does it upload my numbers anywhere?
|
|
281
|
+
|
|
282
|
+
No. The CLI has no network code and records everything under `.cache-verdict/` in your project. To inspect the computed analysis directly:
|
|
283
|
+
|
|
284
|
+
```sh
|
|
285
|
+
cache-verdict report --json
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Can I change the build command or ecosystem?
|
|
289
|
+
|
|
290
|
+
Edit `command`, `inputs`, or `cachePath` in `.cache-verdict.json`, or regenerate the config with `--force`:
|
|
291
|
+
|
|
292
|
+
```sh
|
|
293
|
+
cache-verdict init --force --ecosystem npm --command "npm run build"
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### How do I start over?
|
|
297
|
+
|
|
298
|
+
Remove the measurement directory. The reviewed config stays in place:
|
|
299
|
+
|
|
300
|
+
```sh
|
|
301
|
+
rm -rf .cache-verdict/
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Status
|
|
305
|
+
|
|
306
|
+
Early MVP, version 0.1.0. The features above are the scope; anything not listed is not built yet.
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
311
|
+
|
|
312
|
+
Copyright 2026 WJDdidi-1.
|