How the Proxy Caches
About 479 words
Every request the proxy serves needs two answers from the storage backend before it can fetch the page: which commit to serve, from the repository's index.yaml, and which object the request path maps to, by probing the path and each searchPath variant of it. When the backend answers slowly, waiting for both on every request adds seconds to each page. The proxy keeps both answers in memory, per replica.
The page index
The index of published commits is cached per page domain.
- For 1 minute after it's read, the cached index is served as is.
- After that it's stale but still served: the request that finds it stale gets the cached index right away and starts one refresh in the background. A burst of requests on a stale index starts only one refresh.
- An index nobody asks for is dropped after 1 hour; the next request reads it from the bucket and waits for it.
So a newly uploaded commit becomes visible on a replica at most one request after its index went stale there. The replica that took the upload drops its cached index at once, so it serves the new commit on its next request.
If a refresh fails, the stale index stays cached and the next request that finds it stale tries again.
Path lookups
The proxy also remembers how it resolved each path. A lookup path always contains the commit SHA (<proxy path>/<repository>/<sha>/<path>), and a commit's files don't change after upload, so:
- A path that was found is remembered for 1 hour: later requests for it go straight to the object, with no probes.
- A path the backend definitively doesn't have (every candidate answered
404or410) is remembered for 5 minutes. This covers the configurednotFoundpage as well as the paths bots keep probing. The time limit is shorter because the same commit can be uploaded again with more files, and only the replica that took that upload would otherwise notice. - Nothing else is remembered: a lookup that timed out, a probe the backend answered with an error, or a slow-but-unconfirmed object is probed again on the next request.
The cache holds up to 10,000 lookups per replica and drops the least recently used beyond that.
What this means in practice
- A page's first request after an hour of quiet waits for the backend; the requests after it don't.
- Publishing a new commit never waits for these caches to expire: the commit has a new SHA, so its paths have no cached answers yet.
- Re-uploading files into an existing commit can take up to 5 minutes to show on a replica that already answered
404for them. Publish a new commit instead.
