Skip to content

Ignore Cache-Control when computing the cache key - #369

Open
ahmedalbusaidy wants to merge 1 commit into
dependabot:mainfrom
ahmedalbusaidy:cache-key-ignore-cache-control
Open

ahmedalbusaidy wants to merge 1 commit into
dependabot:mainfrom
ahmedalbusaidy:cache-key-ignore-cache-control

Conversation

@ahmedalbusaidy

Copy link
Copy Markdown

What are you trying to accomplish?

Refs dependabot/smoke-tests#617.

pip 26.2 (pypa/pip#13955) stopped sending Cache-Control: max-age=0 on Simple API index requests; it now sends it only when revalidating. I checked with real clients against a local index: pip 26.1.2 sends Cache-Control: max-age=0, pip 26.2.1 sends no Cache-Control. dependabot-core moved to pip 26.2.1 on 2026-08-28 (dependabot/dependabot-core@4b2a79bb3). Since then the recorded /simple/ pages no longer match: in the hourly smoke (python-pip-compile) run, /simple/ responses served from cache went from 115 to 0 on 2026-08-28, and the test now resolves transitives against live PyPI and drifts with each upstream release (smoke-tests#595 found the same key mismatch).

This leaves Cache-Control out of the cache key, next to Connection, Accept-Encoding and User-Agent, so a client changing its revalidation hints no longer invalidates recordings.

Anything you want to highlight for special attention from reviewers?

  • Existing recordings keep hitting. Keys are stored as hashes, so entries recorded with Cache-Control in the hash wouldn't match the new key. On a miss, OnRequest also tries legacyKey, which still hashes Cache-Control. A legacy hit is served as before and isn't recorded again; a stale legacy entry is dropped and the fresh response is recorded under the new key. This keeps this PR's own Smoke run (which replays the smoke-tests artifacts) and every existing recording unaffected. legacyKey can go once recordings are re-cached; happy to drop it if you'd rather re-cache straight away.
  • pip-compile still needs one re-cache. Its requests no longer carry the header, so neither key matches pages recorded with it; after a Cache One / Cache All run, recordings stop depending on whether a client sends Cache-Control.
  • Conditional headers stay in the key. If-None-Match and If-Modified-Since select between a 200 and a 304 (as discussed in Don't cache conditional/bodyless responses; serve conditional requests from cached 200 #204), so they still change the key; a test covers that.
  • Replay semantics. A request carrying Cache-Control: no-cache or max-age=0 can now be answered from a recorded response. The cache is only enabled with PROXY_CACHE=true; in a live CLI run that means requests repeated within the same job, which already share entries when they carry no Cache-Control.
  • Same idea as Stabilize git-upload-pack cache key by normalizing volatile fields #113: drop volatile client fields from the key, keep what shapes the response.

How will you know you've accomplished your goal?

New tests, each failing without the change:

  • Test_key: a request differing only in Cache-Control: max-age=0 gets the same key; adding If-None-Match still changes it; legacyKey differs from key only when Cache-Control is present.
  • TestCache_RecordedWithCacheControlStillHits: an entry recorded under the legacy key is served, and OnResponse doesn't record it again (fails with two entries if the key is stored before the fallback).
  • TestCache_StaleRecordingWithCacheControlIsReplacedUnderNewKey: a stale legacy entry is replaced under the new key.
  • TestProxyHTTPSCacheIgnoresCacheControl: through the MITM proxy, a response recorded for a request with Cache-Control: max-age=0 is replayed for the same request without it (upstream sees 1 request; 2 on main).

go test -race -shuffle=on -count=2 ./... passes (the command script/test runs, natively rather than in Docker), and the CI lint steps (yamllint ., go mod tidy -diff, gofmt, go build, go vet) are clean.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

pip 26.2 stopped sending "Cache-Control: max-age=0" on Simple API
index requests, so pages recorded with older clients no longer match
the request and the cache falls through to the live registry.

Cache-Control is a revalidation hint and doesn't change the response
the cache replays, so leave it out of the key as with User-Agent.
Conditional headers such as If-None-Match stay in the key because they
select between a 200 and a 304.

Entries recorded with Cache-Control in the key still hit through a
legacy key until they are re-cached. A legacy hit isn't recorded again,
and a stale legacy entry is replaced under the new key.
@ahmedalbusaidy

Copy link
Copy Markdown
Author

The six red Smoke jobs (docker, nix, npm, npm-group-rules, npm-group-semver, python-pip-compile) fail the same way on other PRs. I compared every e2e job in this run with the Smoke run for #355 (https://github.com/dependabot/proxy/actions/runs/43385175631):

  • All 101 jobs have the same conclusion in both runs.
  • 96 jobs report the same calls cached count. The other five (go, hex and three npm jobs) differ by one or two calls in either direction, which matches live upstream traffic rather than a lost match.
  • python-pip-compile is 96/130 in both, as expected until its recordings are re-cached.

The same six jobs fail on the smoke-tests hourly run (https://github.com/dependabot/smoke-tests/actions/workflows/smoke.yml), without the proxy change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant